From: Simon Marchi Date: Wed, 2 Feb 2022 15:54:03 +0000 (-0500) Subject: gdb: include jit_code_entry::symfile_addr value in names of objfiles created by jit... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=4a620b7e;p=binutils-gdb.git gdb: include jit_code_entry::symfile_addr value in names of objfiles created by jit reader API This commit includes the JIT object's symfile address in the names of objfiles created by JIT reader API (e.g., << JIT compiled code at 0x7ffd8a0c77a0 >>). This allows one to at least differentiate one from another. The address is the one that the debugged program has put in jit_code_entry::symfile_addr, and that the JIT reader's read function receives. As we can see in gdb.base/jit-reader-host.c and gdb.base/jit-reader.c, that may not be the actual value of where the JIT-ed code is. But it is a value chosen by the author of the JIT engine and the JIT reader, so including this value in the objfile name may help them correlate the JIT objfiles created by with their logs / data structures. To access this field, we need to pass down a reference to the jit_code_entry. So make jit_dbg_reader_data a structure (instead of an alias for a CORE_ADDR) that includes the address of the code entry in the inferior's address space (the previous meaning of jit_dbg_reader_data) plus a reference to the jit_code_entry as read into GDB's address space. And while at it, pass down the gdbarch, so that we don't have to call target_gdbarch. Co-Authored-By: Jan Vrany Change-Id: Ib26c4d1bd8de503d651aff89ad2e500cb312afa5 --- diff --git a/gdb/jit.c b/gdb/jit.c index 42776b95683..356525443cb 100644 --- a/gdb/jit.c +++ b/gdb/jit.c @@ -380,7 +380,16 @@ struct gdb_object /* The type of the `private' data passed around by the callback functions. */ -typedef CORE_ADDR jit_dbg_reader_data; +struct jit_dbg_reader_data +{ + /* Address of the jit_code_entry in the inferior's address space. */ + CORE_ADDR entry_addr; + + /* The code entry, copied in our address space. */ + const jit_code_entry &entry; + + struct gdbarch *gdbarch; +}; /* The reader calls into this function to read data off the targets address space. */ @@ -623,19 +632,20 @@ static void jit_object_close_impl (struct gdb_symbol_callbacks *cb, struct gdb_object *obj) { - struct objfile *objfile; - jit_dbg_reader_data *priv_data; - - priv_data = (jit_dbg_reader_data *) cb->priv_data; + jit_dbg_reader_data *priv_data = (jit_dbg_reader_data *) cb->priv_data; + std::string objfile_name + = string_printf ("<< JIT compiled code at %s >>", + paddress (priv_data->gdbarch, + priv_data->entry.symfile_addr)); - objfile = objfile::make (nullptr, "<< JIT compiled code >>", - OBJF_NOT_FILENAME); - objfile->per_bfd->gdbarch = target_gdbarch (); + objfile *objfile = objfile::make (nullptr, objfile_name.c_str (), + OBJF_NOT_FILENAME); + objfile->per_bfd->gdbarch = priv_data->gdbarch; for (gdb_symtab &symtab : obj->symtabs) finalize_symtab (&symtab, objfile); - add_objfile_entry (objfile, *priv_data); + add_objfile_entry (objfile, priv_data->entry_addr); delete obj; } @@ -645,11 +655,16 @@ jit_object_close_impl (struct gdb_symbol_callbacks *cb, inferior address space. */ static int -jit_reader_try_read_symtab (struct jit_code_entry *code_entry, +jit_reader_try_read_symtab (gdbarch *gdbarch, jit_code_entry *code_entry, CORE_ADDR entry_addr) { int status; - jit_dbg_reader_data priv_data; + jit_dbg_reader_data priv_data + { + entry_addr, + *code_entry, + gdbarch + }; struct gdb_reader_funcs *funcs; struct gdb_symbol_callbacks callbacks = { @@ -665,8 +680,6 @@ jit_reader_try_read_symtab (struct jit_code_entry *code_entry, &priv_data }; - priv_data = entry_addr; - if (!loaded_jit_reader) return 0; @@ -779,7 +792,7 @@ jit_register_code (struct gdbarch *gdbarch, paddress (gdbarch, code_entry->symfile_addr), pulongest (code_entry->symfile_size)); - success = jit_reader_try_read_symtab (code_entry, entry_addr); + success = jit_reader_try_read_symtab (gdbarch, code_entry, entry_addr); if (!success) jit_bfd_try_read_symtab (code_entry, entry_addr, gdbarch); diff --git a/gdb/testsuite/gdb.base/jit-reader.exp b/gdb/testsuite/gdb.base/jit-reader.exp index bcc85640ec0..d94360cd7d9 100644 --- a/gdb/testsuite/gdb.base/jit-reader.exp +++ b/gdb/testsuite/gdb.base/jit-reader.exp @@ -230,11 +230,11 @@ proc jit_reader_test {} { if { ![skip_python_tests] } { gdb_test "python print(gdb.objfiles())" \ - "$any>>$any" \ + "$any>>$any" \ "python gdb.Objfile.__repr__ ()" gdb_test "python print(list(map(lambda objf : objf.filename, gdb.objfiles())))" \ - "$any'<< JIT compiled code >>'$any" \ + "$any'<< JIT compiled code at $hex >>'$any" \ "python gdb.Objfile.filename" } }