]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: include jit_code_entry::symfile_addr value in names of objfiles created by jit...
authorSimon Marchi <simon.marchi@efficios.com>
Wed, 2 Feb 2022 15:54:03 +0000 (10:54 -0500)
committerSimon Marchi <simon.marchi@polymtl.ca>
Fri, 4 Feb 2022 16:07:37 +0000 (11:07 -0500)
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 <jan.vrany@labware.com>
Change-Id: Ib26c4d1bd8de503d651aff89ad2e500cb312afa5

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

index 42776b956832fb149c4997ca685be4ec460b9520..356525443cb246f9ca172d00f3fc52389387e60e 100644 (file)
--- 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);
index bcc85640ec092819ac7f56944f90eb7dbd0f99cb..d94360cd7d9e193aab8a142d92b46ba91edebbbe 100644 (file)
@@ -230,11 +230,11 @@ proc jit_reader_test {} {
 
            if { ![skip_python_tests] } {
                gdb_test "python print(gdb.objfiles())" \
-                   "$any<gdb.Objfile filename=<< JIT compiled code >>>$any" \
+                   "$any<gdb.Objfile filename=<< JIT compiled code at $hex >>>$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"
            }
        }