[v2] gdb/jit: fix jit-reader linetable integrity
Checks
Context |
Check |
Description |
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 |
success
|
Build passed
|
Commit Message
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.
---
gdb/jit.c | 2 ++
1 file changed, 2 insertions(+)
Comments
Simon,
I know you said you were looking at writing a test for this, but I'd
like to see this patch land in the gdb-16-branch, so I thought I'd take
a quick look too.
The patch below, which is Yang Liu's original change, plus a very
minimal test from me.
As far as I can tell we had no testing for using the line_mapping_add
callback in the jit api, so the approach I've taken is to add just a
couple of line table entries. By adding entries for just a couple of
addresses then the test never actually stops at one of these lines, but
GDB still has to search over these entries in order to figure that out.
This means that the bug still triggers, but the testsuite changes are
minimal.
If you're happy with this for now, then I propose that we merge this to
master and gdb-16-branch, then I'd be willing to follow up with a
_slightly_ bigger test that covers more of the jit line number api
(e.g. includes a test that actually hits one of the lines from the
table). Of course, if you already have a bigger & better test that's
ready to go, we can just land that. Or you bigger/better test could be
the follow up?
Thoughts?
Thanks,
Andrew
---
commit ca3f3421b92c0a164ebf0e876d22247583a7a57b
Author: Yang Liu <liuyang22@iscas.ac.cn>
Date: Mon Dec 23 00:33:30 2024 +0800
gdb/jit: fix jit-reader linetable integrity
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.
diff --git a/gdb/jit.c b/gdb/jit.c
index 77d41bf86ba..21c17c145c9 100644
--- 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)
diff --git a/gdb/testsuite/gdb.base/jit-reader.c b/gdb/testsuite/gdb.base/jit-reader.c
index 414be072a67..e8dd8ccddd9 100644
--- a/gdb/testsuite/gdb.base/jit-reader.c
+++ b/gdb/testsuite/gdb.base/jit-reader.c
@@ -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 non 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,
>>>>> "Andrew" == Andrew Burgess <aburgess@redhat.com> writes:
Andrew> If you're happy with this for now, then I propose that we merge this to
Andrew> master and gdb-16-branch, then I'd be willing to follow up with a
Andrew> _slightly_ bigger test that covers more of the jit line number api
Makes sense to me.
Andrew> + information is constructed such that non of the tests actually hit any
s/non/none
Anyway I think this is OK. Thank you for doing this.
Approved-By: Tom Tromey <tom@tromey.com>
Tom
Tom Tromey <tom@tromey.com> writes:
>>>>>> "Andrew" == Andrew Burgess <aburgess@redhat.com> writes:
>
> Andrew> If you're happy with this for now, then I propose that we merge this to
> Andrew> master and gdb-16-branch, then I'd be willing to follow up with a
> Andrew> _slightly_ bigger test that covers more of the jit line number api
>
> Makes sense to me.
>
> Andrew> + information is constructed such that non of the tests actually hit any
>
> s/non/none
>
> Anyway I think this is OK. Thank you for doing this.
> Approved-By: Tom Tromey <tom@tromey.com>
Thanks. I pushed this to master and gdb-16-branch.
Thanks,
Andrew
@@ -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)