From: Jan Vrany <jan.vrany@labware.com>
To: gdb-patches@sourceware.org
Cc: Jan Vrany <jan.vrany@labware.com>, Tom Tromey <tom@tromey.com>
Subject: [RFC v5 03/18] gdb: update is_addr_in_objfile to support "dynamic" objfiles
Date: Mon, 23 Jun 2025 17:09:58 +0100 [thread overview]
Message-ID: <20250623161013.650814-4-jan.vrany@labware.com> (raw)
In-Reply-To: <20250623161013.650814-1-jan.vrany@labware.com>
While working with objfiles in Python I noticed that
gdb.Progspace.objfile_for_address () does not return "dynamic" objfiles
created by (for example) GDB's JIT reader API.
This is because is_addr_in_objfile() checks if a 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 the address fall into any compunit in that objfile. It does so
only if the objfile has no sections.
Approved-By: Tom Tromey <tom@tromey.com>
---
gdb/objfiles.c | 14 ++++++++++++++
gdb/objfiles.h | 7 +++++++
gdb/testsuite/gdb.base/jit-reader.exp | 9 +++++++++
3 files changed, 30 insertions(+)
diff --git a/gdb/objfiles.c b/gdb/objfiles.c
index d25d1a02cea..6d5dd588f91 100644
--- a/gdb/objfiles.c
+++ b/gdb/objfiles.c
@@ -1135,6 +1135,20 @@ 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 any of them contains given ADDR. */
+ if (objfile->sections_start == nullptr)
+ {
+ for (const compunit_symtab *cu : objfile->compunits ())
+ {
+ if (cu->maybe_contains (addr))
+ return true;
+ }
+ }
return false;
}
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index 0206b49e00c..cadb4525782 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -459,6 +459,13 @@ struct objfile : intrusive_list_node<objfile>
return compunit_symtab_range (compunit_symtabs);
}
+ /* Const version of the function above. */
+
+ compunit_symtab_range compunits () const
+ {
+ return compunit_symtab_range (compunit_symtabs);
+ }
+
/* A range adapter that makes it possible to iterate over all
minimal symbols of an objfile. */
diff --git a/gdb/testsuite/gdb.base/jit-reader.exp b/gdb/testsuite/gdb.base/jit-reader.exp
index 4462ab4aa65..8399558403a 100644
--- a/gdb/testsuite/gdb.base/jit-reader.exp
+++ b/gdb/testsuite/gdb.base/jit-reader.exp
@@ -233,6 +233,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"
}
}
}
--
2.47.2
next prev parent reply other threads:[~2025-06-23 16:13 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-23 16:09 [RFC v5 00/19] Add Python "JIT" API Jan Vrany
2025-06-23 16:09 ` [RFC v5 01/18] gdb: introduce expand_symtabs_maybe_overlapping Jan Vrany
2025-06-24 15:22 ` Tom Tromey
2025-06-26 15:05 ` Jan Vraný
2025-06-23 16:09 ` [RFC v5 02/18] gdb: introduce compunit_symtab::maybe_contains Jan Vrany
2025-06-23 16:09 ` Jan Vrany [this message]
2025-06-23 16:09 ` [RFC v5 04/18] gdb: introduce new function create_function_type Jan Vrany
2025-06-24 15:29 ` Tom Tromey
2025-06-26 11:12 ` Jan Vraný
2025-06-27 14:21 ` Tom Tromey
2025-06-27 14:30 ` Jan Vraný
2025-06-23 16:10 ` [RFC v5 05/18] gdb/python: add function () method to gdb.Type object Jan Vrany
2025-06-24 16:11 ` Tom Tromey
2025-06-26 11:13 ` Jan Vraný
2025-06-23 16:10 ` [RFC v5 06/18] gdb: use std::vector<> to hold on blocks in struct blockvector Jan Vrany
2025-06-23 16:10 ` [RFC v5 07/18] gdb/python: add gdb.Compunit Jan Vrany
2025-06-23 16:10 ` [RFC v5 08/18] gdb/python: allow instantiation of gdb.Objfile from Python Jan Vrany
2025-06-23 16:10 ` [RFC v5 09/18] gdb/python: add unlink () method to gdb.Objfile object Jan Vrany
2025-06-23 16:10 ` [RFC v5 10/18] gdb/python: allow instantiation of gdb.Compunit from Python Jan Vrany
2025-06-23 16:10 ` [RFC v5 11/18] gdb/python: allow instantiation of gdb.Symtab " Jan Vrany
2025-06-23 16:10 ` [RFC v5 12/18] gdb/python: allow instantiation of gdb.Block " Jan Vrany
2025-06-23 16:10 ` [RFC v5 13/18] gdb/python: allow instantiation of gdb.Symbol " Jan Vrany
2025-06-23 16:10 ` [RFC v5 14/18] gdb/python: add add_symbol () method to gdb.Block Jan Vrany
2025-08-29 14:10 ` Andrew Burgess
2025-08-29 14:14 ` Andrew Burgess
2025-06-23 16:10 ` [RFC v5 15/18] gdb/python: add more attributes to gdb.LinetableEntry objects Jan Vrany
2025-08-29 14:00 ` Andrew Burgess
2025-09-02 11:03 ` Jan Vraný
2025-06-23 16:10 ` [RFC v5 16/18] gdb/python: allow instantiation of gdb.LineTableEntry objects Jan Vrany
2025-06-23 16:10 ` [RFC v5 17/18] gdb/python: allow instantiation of gdb.LineTable objects Jan Vrany
2025-06-23 16:10 ` [RFC v5 18/18] gdb/python: add section in documentation on implementing JIT interface Jan Vrany
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250623161013.650814-4-jan.vrany@labware.com \
--to=jan.vrany@labware.com \
--cc=gdb-patches@sourceware.org \
--cc=tom@tromey.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox