]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/jit: fix jit-reader linetable integrity
authorYang Liu <liuyang22@iscas.ac.cn>
Sun, 22 Dec 2024 16:33:30 +0000 (00:33 +0800)
committerAndrew Burgess <aburgess@redhat.com>
Tue, 14 Jan 2025 18:02:19 +0000 (18:02 +0000)
The custom linetable functionality in GDB's JIT Interface has been broken
since commit 1acc9dca423f78e44553928f0de839b618c13766.

In that commit, linetables were made independent from the objfile, which
requires objfile->section_offsets to be initialized. However, section_offsets
were never initialized in objfiles generated by GDB's JIT Interface
with custom jit-readers, leading to GDB crashes when stepping into JITed code
blocks with the following command already executed:

  jit-reader-load libmygdbjitreader.so

This patch fixes the issue by initializing the minimum section_offsets required
for linetable parsing procedures.

A minimal test is included.  The test sets up some very simple line
table information, which is enough to trigger the bug.  However, the
line table information is crafted such that none of the line table
entries will end up being displayed in GDB's output when the test is
run, as such, none of the expected output actually changes.

It might be nice in the future to extend some of the jit tests to
actually test hitting line table entries added via the jit reader.

Approved-By: Tom Tromey <tom@tromey.com>
gdb/jit.c
gdb/testsuite/gdb.base/jit-reader.c

index 39c17a5ab989aaa206df293c6193ed494d62b408..9736f84cf873011e349c2104c7c910b4a7878535 100644 (file)
--- a/gdb/jit.c
+++ b/gdb/jit.c
@@ -665,6 +665,8 @@ jit_object_close_impl (struct gdb_symbol_callbacks *cb,
 
   objfile *objfile = objfile::make (nullptr, current_program_space,
                                    objfile_name.c_str (), OBJF_NOT_FILENAME);
+  objfile->section_offsets.push_back (0);
+  objfile->sect_index_text = 0;
   objfile->per_bfd->gdbarch = priv_data->gdbarch;
 
   for (gdb_symtab &symtab : obj->symtabs)
index 414be072a67ef6c13e73d8dd76e6928e3892cba2..78117f0417949ea5b4eacb01dd823624ba40dc90 100644 (file)
@@ -62,6 +62,18 @@ read_debug_info (struct gdb_reader_funcs *self,
                   (GDB_CORE_ADDR) symfile->function_stack_mangle.end,
                   "jit_function_stack_mangle");
 
+  /* Add some line table information.  This ensures that GDB can handle
+     accepting this information, and can scan the table.  However, this
+     information is constructed such that none of the tests actually hit any
+     of these line entries.  */
+  struct gdb_line_mapping mangle_lines[] =
+    {
+      { 1, (GDB_CORE_ADDR) symfile->function_stack_mangle.begin + 0 },
+      { 0, (GDB_CORE_ADDR) symfile->function_stack_mangle.begin + 1 },
+    };
+  int mangle_nlines = sizeof (mangle_lines) / sizeof (mangle_lines[0]);
+  cbs->line_mapping_add (cbs, symtab, mangle_nlines, mangle_lines);
+
   cbs->block_open (cbs, symtab, NULL,
                   (GDB_CORE_ADDR) symfile->function_add.begin,
                   (GDB_CORE_ADDR) symfile->function_add.end,