]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: get jiter objfile from a bound minsym
authorMihails Strasuns <mihails.strasuns@intel.com>
Wed, 14 Oct 2020 08:44:36 +0000 (10:44 +0200)
committerMihails Strasuns <mihails.strasuns@intel.com>
Mon, 19 Oct 2020 14:46:44 +0000 (16:46 +0200)
This fixes a regression introduced by the following commit:

fe053b9e853 gdb/jit: pass the jiter objfile as an argument to jit_event_handler

In the refactoring `handle_jit_event` function was changed to pass a matching
objfile pointer to the `jit_event_handler` explicitly, rather using internal
storage:

```
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -5448,8 +5448,9 @@ handle_jit_event (void)

   frame = get_current_frame ();
   gdbarch = get_frame_arch (frame);
+  objfile *jiter = symbol_objfile (get_frame_function (frame));

-  jit_event_handler (gdbarch);
+  jit_event_handler (gdbarch, jiter);
```

This was needed to add support for multiple jiters.  However it has also
introduced a regression, because `get_frame_function (frame)` here may
return `nullptr`, resulting in a crash.

A more resilient way would be to use an approach mirroring
`jit_breakpoint_re_set` - to find a minimal symbol matching the
breakpoint location and use its object file.  We know that this
breakpoint event comes from a breakpoint set by `jit_breakpoint_re_set`,
thus using the reverse approach should be reliable enough.

gdb/Changelog:
2020-10-14  Mihails Strasuns  <mihails.strasuns@intel.com>

* breakpoint.c (handle_jit_event): Add an argument, change how
`jit_event_handler` is called.

gdb/ChangeLog
gdb/breakpoint.c

index 4eed6920ae5cbb8536150e00ac8b5c75bbf84631..c5c41bf4ecd67bdeb89e7d29ce666e24a0c9cdb1 100644 (file)
@@ -1,3 +1,8 @@
+2020-10-14  Mihails Strasuns  <mihails.strasuns@intel.com>
+
+       * breakpoint.c (handle_jit_event): Add an argument, change how
+       `jit_event_handler` is called.
+
 2020-10-13  Simon Marchi  <simon.marchi@polymtl.ca>
 
        PR gdb/26642
index 3fb259ff40964f1442d69121536957ae40b6fe5b..f304c0c355917b3910524dafabd77b2865dc298c 100644 (file)
@@ -5441,9 +5441,8 @@ bpstat_stop_status (const address_space *aspace,
 }
 
 static void
-handle_jit_event (void)
+handle_jit_event (CORE_ADDR address)
 {
-  struct frame_info *frame;
   struct gdbarch *gdbarch;
 
   infrun_debug_printf ("handling bp_jit_event");
@@ -5452,11 +5451,15 @@ handle_jit_event (void)
      breakpoint_re_set.  */
   target_terminal::ours_for_output ();
 
-  frame = get_current_frame ();
-  gdbarch = get_frame_arch (frame);
-  objfile *jiter = symbol_objfile (get_frame_function (frame));
-
-  jit_event_handler (gdbarch, jiter);
+  gdbarch = get_frame_arch (get_current_frame ());
+  /* This event is caused by a breakpoint set in `jit_breakpoint_re_set`,
+     thus it is expected that its objectfile can be found through
+     minimal symbol lookup.  If it doesn't work (and assert fails), it
+     most likely means that `jit_breakpoint_re_set` was changes and this
+     function needs to be updated too.  */
+  bound_minimal_symbol jit_bp_sym = lookup_minimal_symbol_by_pc (address);
+  gdb_assert (jit_bp_sym.objfile != nullptr);
+  jit_event_handler (gdbarch, jit_bp_sym.objfile);
 
   target_terminal::inferior ();
 }
@@ -5657,7 +5660,7 @@ bpstat_run_callbacks (bpstat bs_head)
       switch (b->type)
        {
        case bp_jit_event:
-         handle_jit_event ();
+         handle_jit_event (bs->bp_location_at->address);
          break;
        case bp_gnu_ifunc_resolver:
          gnu_ifunc_resolver_stop (b);