From: Jan Vrany Date: Thu, 21 Nov 2024 12:31:20 +0000 (+0000) Subject: gdb: update is_addr_in_objfile to support "dynamic" objfiles X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0d2f828428cb71f397c5759232988081ac202477;p=thirdparty%2Fbinutils-gdb.git gdb: update is_addr_in_objfile to support "dynamic" objfiles 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. --- diff --git a/gdb/objfiles.c b/gdb/objfiles.c index 555195dc61f..0bb578fa6a8 100644 --- a/gdb/objfiles.c +++ b/gdb/objfiles.c @@ -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(objfile)->compunits ()) + { + global_block *gb = cu->blockvector ()->global_block (); + if (gb->start () <= addr && addr <= gb->end ()) + return true; + } + } return false; } diff --git a/gdb/testsuite/gdb.base/jit-reader.exp b/gdb/testsuite/gdb.base/jit-reader.exp index 62f6af29ac1..9a873c77909 100644 --- a/gdb/testsuite/gdb.base/jit-reader.exp +++ b/gdb/testsuite/gdb.base/jit-reader.exp @@ -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')) )" \ + ">>" \ + "python gdb.Progspace.objfile_for_address" } } }