[PATCH] use an observer instead of deprecated_file_changed_hook

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH] use an observer instead of deprecated_file_changed_hook

Tom Tromey
This patch changes Insight to use the new_objfile observer rather than
deprecated_file_changed_hook.  This will let us remove
deprecated_file_changed_hook from gdb.

I think it works ok.  I tested it by running the "file" command in the
console and seeing whether insight reacted.  I'm not totally sure
whether this is a sufficient check, though.

Ok?

Tom

gdb/gdbtk/ChangeLog:
2014-01-07  Tom Tromey  <[hidden email]>

        * generic/gdbtk-hooks.c (gdbtk_new_objfile): New function.
        (gdbtk_file_changed): Remove.
        (gdbtk_add_hooks): Register "new_objfile" observer.  Don't set
        deprecated_file_changed_hook.

Index: gdb/gdbtk/generic/gdbtk-hooks.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/generic/gdbtk-hooks.c,v
retrieving revision 1.60
diff -u -r1.60 gdbtk-hooks.c
--- gdb/gdbtk/generic/gdbtk-hooks.c 2 Jul 2013 17:07:29 -0000 1.60
+++ gdb/gdbtk/generic/gdbtk-hooks.c 7 Jan 2014 19:07:52 -0000
@@ -1,7 +1,7 @@
 /* Startup code for Insight.
 
    Copyright (C) 1994, 1995, 1996, 1997, 1998, 2000, 200, 2002, 2003, 2004,
-   2008, 2010, 2011, 2012, 2013 Free Software Foundation, Inc.
+   2008, 2010, 2011, 2012, 2013, 2014 Free Software Foundation, Inc.
 
    Written by Stu Grossman <[hidden email]> of Cygnus Support.
 
@@ -77,7 +77,7 @@
 static void gdbtk_trace_start_stop (int, int);
 static void gdbtk_attach (void);
 static void gdbtk_detach (void);
-static void gdbtk_file_changed (char *);
+static void gdbtk_new_objfile (struct objfile *);
 static void gdbtk_exec_file_display (char *);
 static void gdbtk_call_command (struct cmd_list_element *, char *, int);
 static ptid_t gdbtk_wait (ptid_t, struct target_waitstatus *, int);
@@ -144,7 +144,8 @@
   deprecated_ui_loop_hook = x_event;
   deprecated_pre_add_symbol_hook = gdbtk_pre_add_symbol;
   deprecated_post_add_symbol_hook = gdbtk_post_add_symbol;
-  deprecated_file_changed_hook = gdbtk_file_changed;
+  observer_attach_new_objfile (gdbtk_new_objfile);
+
   specify_exec_file_hook (gdbtk_exec_file_display);
 
   deprecated_trace_find_hook = gdbtk_trace_find;
@@ -764,11 +765,12 @@
   gdb_context = num;
 }
 
-/* Called from file_command */
+/* Called from file_command, via the symfile observer.  */
 static void
-gdbtk_file_changed (char *filename)
+gdbtk_new_objfile (struct objfile *objfile)
 {
-  gdbtk_two_elem_cmd ("gdbtk_tcl_file_changed", filename);
+  if (objfile == symfile_objfile && objfile != NULL)
+    gdbtk_two_elem_cmd ("gdbtk_tcl_file_changed", objfile->original_name);
 }
 
 /* Called from exec_file_command */
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] use an observer instead of deprecated_file_changed_hook

Keith Seitz
On 01/07/2014 11:09 AM, Tom Tromey wrote:
> I think it works ok.  I tested it by running the "file" command in the
> console and seeing whether insight reacted.  I'm not totally sure
> whether this is a sufficient check, though.

With the additional checks you've added in the observer function, this
should work.

The standard test (IIRC -- I haven't tried this in years) is to start
insight on one executable, debug it a bit (run, step, step, step) with
some open data windows, then load an entirely new executable. If that
runs and the displays all show the new executable's state, then all is
probably good. I believe I also then followed with "file" (no
executable), which should simple clear state and "empty" all the windows.

 From discussions on IRC, this use case is preserved. So that's good
enough for me.

Thank you for the patch!
Keith

Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] use an observer instead of deprecated_file_changed_hook

Tom Tromey
>>>>> "Keith" == Keith Seitz <[hidden email]> writes:

Keith> I believe I also then followed with "file" (no
Keith> executable), which should simple clear state and "empty" all the
Keith> windows.

This one failed with my patch.  I'm trying a new patch to see if I can
make it work reasonably well with the existing observers.  I'll let you
know.

Tom
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] use an observer instead of deprecated_file_changed_hook

Tom Tromey
Tom> This one failed with my patch.  I'm trying a new patch to see if I can
Tom> make it work reasonably well with the existing observers.  I'll let you
Tom> know.

I thought I could make it work by also using the free_objfile observer,
but that observer is not in the old CVS repository.  So until Insight
has its own git repository and can be based on the latest gdb, no joy
here.

I'm appending my current patch for reference.  I can't test it though.

Tom

Index: gdbtk-hooks.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/generic/gdbtk-hooks.c,v
retrieving revision 1.60
diff -u -c -r1.60 gdbtk-hooks.c
cvs diff: conflicting specifications of output style
--- gdbtk-hooks.c 2 Jul 2013 17:07:29 -0000 1.60
+++ gdbtk-hooks.c 9 Jan 2014 17:24:28 -0000
@@ -1,7 +1,7 @@
 /* Startup code for Insight.
 
    Copyright (C) 1994, 1995, 1996, 1997, 1998, 2000, 200, 2002, 2003, 2004,
-   2008, 2010, 2011, 2012, 2013 Free Software Foundation, Inc.
+   2008, 2010, 2011, 2012, 2013, 2014 Free Software Foundation, Inc.
 
    Written by Stu Grossman <[hidden email]> of Cygnus Support.
 
@@ -77,7 +77,8 @@
 static void gdbtk_trace_start_stop (int, int);
 static void gdbtk_attach (void);
 static void gdbtk_detach (void);
-static void gdbtk_file_changed (char *);
+static void gdbtk_new_objfile (struct objfile *);
+static void gdbtk_objfile_removed (struct objfile *);
 static void gdbtk_exec_file_display (char *);
 static void gdbtk_call_command (struct cmd_list_element *, char *, int);
 static ptid_t gdbtk_wait (ptid_t, struct target_waitstatus *, int);
@@ -144,7 +145,9 @@
   deprecated_ui_loop_hook = x_event;
   deprecated_pre_add_symbol_hook = gdbtk_pre_add_symbol;
   deprecated_post_add_symbol_hook = gdbtk_post_add_symbol;
-  deprecated_file_changed_hook = gdbtk_file_changed;
+  observer_attach_new_objfile (gdbtk_new_objfile);
+  observer_attach_free_objfile (gdbtk_objfile_removed);
+
   specify_exec_file_hook (gdbtk_exec_file_display);
 
   deprecated_trace_find_hook = gdbtk_trace_find;
@@ -764,11 +767,23 @@
   gdb_context = num;
 }
 
-/* Called from file_command */
+/* Called from file_command, via the new objfile observer.  */
+static void
+gdbtk_new_objfile (struct objfile *objfile)
+{
+  if (objfile == symfile_objfile && objfile != NULL)
+    gdbtk_two_elem_cmd ("gdbtk_tcl_file_changed",
+ objfile == NULL ? NULL : objfile->original_name);
+}
+
+/* Called from file_command, via the free objfile observer.  */
 static void
-gdbtk_file_changed (char *filename)
+gdbtk_objfile_removed (struct objfile *objfile)
 {
-  gdbtk_two_elem_cmd ("gdbtk_tcl_file_changed", filename);
+  static int symfile_was_set;
+
+  if (objfile == symfile_objfile)
+    gdbtk_two_elem_cmd ("gdbtk_tcl_file_changed", NULL);
 }
 
 /* Called from exec_file_command */