This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[commit] Breakpoint in shared library does not work on mips-irix


Trying to insert a breakpoint inside a share library does not always
work on mips-irix.  The problem occurs when the code is being executed
during the -init phase of the shared library.  As a result, breakpoints
inserted in the elaboration phase of Ada units provided by a shared library
ineffective.

There is a rather large comment in procfs_init_inferior which explains
that the enable_break breakpoint set by solib-irix in order to wait
until shared libraries are loaded only gets hit *after* the SOs -init
code is executed, which is too late in our case. As a result, we enable
syssgi() sys-exit notifications to help us stop the execution in time
in order to insert another breakpoint (inside rld, the loader).
      
But it turned out that we never received these events! It turned out
that we were disabling these notifiations too early: We were doing it
at the end of procfs_create_inferior, after the call to procfs_init_inferior.
At this point, we have run the inferior long enough to get the 2 EXEC
notifications, but not long enough to have reached the syssgi exit
notification.

The solution was to introduce an "inferior_created" observer. This event
is broadcast a little later, after the solib_inferior_hook has been run.
At this point, we know that we will no longer need that notification
anymore, and thus we can disable it safely.  There is one thing that
we need to be careful of, however: It is the fact that the even occurs
regardless of how the inferior was created - as a result, we have to be
careful to do this only after having spawned the inferior ourselves,
not after having attached to a process or while debugging a core file.
   
As an aside, the did-we-spawn-the-inferior predicate seems to be used
fairly frequently.  Looking at various solib implementations, for instance,
it seems sufficiently standard that I am considering the idea of making
this an inferior flag that we can then simply test. For a rainy day?...

gdb/ChangeLog:

        Breakpoint in shared library does not work on mips-irix.
        * procfs.c: #include "observer.h".
        (procfs_inferior_created): New function, moving here the code
        which unsets the syssgi syscall-exit notifications.
        (procfs_create_inferior): Remove the code which unsets the syssgi
        syscall-exit notifications. It is too early to do this here.
        (_initialize_procfs): Attach the procfs_inferior_created observer.

-- 
Joel
gdb/ChangeLog:

        Breakpoint in shared library does not work on mips-irix.
        * procfs.c: #include "observer.h".
        (procfs_inferior_created): New function, moving here the code
        which unsets the syssgi syscall-exit notifications.
        (procfs_create_inferior): Remove the code which unsets the syssgi
        syscall-exit notifications. It is too early to do this here.
        (_initialize_procfs): Attach the procfs_inferior_created observer.
---
 gdb/procfs.c |   19 ++++++++++++++++++-
 1 files changed, 18 insertions(+), 1 deletions(-)

diff --git a/gdb/procfs.c b/gdb/procfs.c
index 5791ee7..9278bcb 100644
--- a/gdb/procfs.c
+++ b/gdb/procfs.c
@@ -51,6 +51,7 @@
 #include "inflow.h"
 #include "auxv.h"
 #include "procfs.h"
+#include "observer.h"
 
 /*
  * PROCFS.C
@@ -5146,13 +5147,27 @@ procfs_create_inferior (struct target_ops *ops, char *exec_file,
 		       NULL, NULL, shell_file);
 
   procfs_init_inferior (ops, pid);
+}
+
+/* An observer for the "inferior_created" event.  */
 
+static void
+procfs_inferior_created (struct target_ops *ops, int from_tty)
+{
 #ifdef SYS_syssgi
   /* Make sure to cancel the syssgi() syscall-exit notifications.  
      They should normally have been removed by now, but they may still
      be activated if the inferior doesn't use shared libraries, or if
      we didn't locate __dbx_link, or if we never stopped in __dbx_link.
-     See procfs_init_inferior() for more details.  */
+     See procfs_init_inferior() for more details.
+
+     Since these notifications are only ever enabled when we spawned
+     the inferior ourselves, there is nothing to do when the inferior
+     was created by attaching to an already running process, or when
+     debugging a core file.  */
+  if (current_inferior ()->attach_flag || !target_can_run (&current_target))
+    return;
+
   proc_trace_syscalls_1 (find_procinfo_or_die (PIDGET (inferior_ptid), 0),
                          SYS_syssgi, PR_SYSEXIT, FLAG_RESET, 0);
 #endif
@@ -6000,6 +6015,8 @@ proc_untrace_sysexit_cmd (char *args, int from_tty)
 void
 _initialize_procfs (void)
 {
+  observer_attach_inferior_created (procfs_inferior_created);
+
   add_info ("proc", info_proc_cmd, _("\
 Show /proc process information about any running process.\n\
 Specify process id, or use the program being debugged by default.\n\
-- 
1.5.4.3


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]