]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: update is_addr_in_objfile to support "dynamic" objfiles
authorJan Vrany <jan.vrany@labware.com>
Thu, 21 Nov 2024 12:31:20 +0000 (12:31 +0000)
committerJan Vrany <jan.vrany@labware.com>
Thu, 21 Nov 2024 12:31:20 +0000 (12:31 +0000)
While working with objfiles in Python I noticed that
gdb.Progspace.objfile_for_address () does not return "dynamic" objfile
create by (for example) GDB's JIT reader API.

This is because is_addr_in_objfile() checks if given address falls into
any (mappped) section of that objfile. However objfiles created by JIT
reader API do not have sections.

To solve this issue, this commit updates is_addr_in_objfile() to also
check if address fall into any compunit if that objfile. It does so only
if objfile has no sections.

gdb/objfiles.c
gdb/testsuite/gdb.base/jit-reader.exp

index 555195dc61f9f88aa456ae473d3102a8a0f6b4a4..0bb578fa6a89d434ae7ead38d2ee712d1e9ba80a 100644 (file)
@@ -1194,6 +1194,22 @@ is_addr_in_objfile (CORE_ADDR addr, const struct objfile *objfile)
       if (osect->contains (addr))
        return true;
     }
+  /* Objfiles created dynamically by JIT reader API (and possibly by
+     other means too) do not have sections and therefore the above
+     check never succeeds.
+
+     For such "dynamic" objfiles walk over all compunits and check
+     if given ADDR falls into compunit's global block.  */
+  if (! objfile->sections_start)
+    {
+      for (compunit_symtab *cu
+            : const_cast<struct objfile *>(objfile)->compunits ())
+       {
+         global_block *gb = cu->blockvector ()->global_block ();
+         if (gb->start () <= addr && addr <= gb->end ())
+           return true;
+       }
+    }
   return false;
 }
 
index 62f6af29ac15a2245e2a99c5ab40a0eaf59ec310..9a873c77909149207e32349c202f308d3ca96bfd 100644 (file)
@@ -229,6 +229,15 @@ proc jit_reader_test {} {
                gdb_test "python print( \[o for o in gdb.objfiles() if o.filename.startswith('<< JIT compiled code')\]\[0\].build_id )" \
                    "None" \
                    "python gdb.Objfile.build_id"
+
+               # Check that Progspace.objfile_for_address () finds "jitted"
+               # objfile
+               gdb_test "frame 0" \
+                   "#0  $hex in jit_function_stack_mangle ()$any" \
+                   "select frame 0"
+               gdb_test "python print( gdb.current_progspace().objfile_for_address(gdb.parse_and_eval('\$pc')) )" \
+                   "<gdb.Objfile filename=<< JIT compiled code at $hex >>>" \
+                   "python gdb.Progspace.objfile_for_address"
            }
        }
     }