From b4647f1c46b900be8bffe0a7848aa64e5f42e846 Mon Sep 17 00:00:00 2001 From: Bruno Larsen Date: Thu, 30 Mar 2023 12:07:21 +0200 Subject: [PATCH] Backport "[gdb/breakpoint] Fix assert in jit_event_handler" Resolves: rhbz#2130624 --- _gdb.spec.Patch.include | 4 + _gdb.spec.patch.include | 1 + _patch_order | 1 + ...-2130624-assert_in_jit_event_handler.patch | 115 ++++++++++++++++++ gdb.spec | 4 + 5 files changed, 125 insertions(+) create mode 100644 gdb-rhbz-2130624-assert_in_jit_event_handler.patch diff --git a/_gdb.spec.Patch.include b/_gdb.spec.Patch.include index 69bc5a1..6692ef2 100644 --- a/_gdb.spec.Patch.include +++ b/_gdb.spec.Patch.include @@ -471,3 +471,7 @@ Patch113: gdb-rhbz2155439-assert-failure-copy_type.patch # (Tom de Vries) Patch114: gdb-fix-gdb.base-printcmds-s390x-regressions.patch +# Backport "[gdb/breakpoint] Fix assert in jit_event_handler" +# (Tom de Vries, RHBZ2130624) +Patch115: gdb-rhbz-2130624-assert_in_jit_event_handler.patch + diff --git a/_gdb.spec.patch.include b/_gdb.spec.patch.include index afc8a74..b65d5b4 100644 --- a/_gdb.spec.patch.include +++ b/_gdb.spec.patch.include @@ -112,3 +112,4 @@ %patch112 -p1 %patch113 -p1 %patch114 -p1 +%patch115 -p1 diff --git a/_patch_order b/_patch_order index adc0f9c..1ddd7c9 100644 --- a/_patch_order +++ b/_patch_order @@ -112,3 +112,4 @@ gdb-rhbz1870017-p10-plt-prologue-skipping.patch gdb-rhbz2086761-unknown-cfa-rule.patch gdb-rhbz2155439-assert-failure-copy_type.patch gdb-fix-gdb.base-printcmds-s390x-regressions.patch +gdb-rhbz-2130624-assert_in_jit_event_handler.patch diff --git a/gdb-rhbz-2130624-assert_in_jit_event_handler.patch b/gdb-rhbz-2130624-assert_in_jit_event_handler.patch new file mode 100644 index 0000000..488aaa3 --- /dev/null +++ b/gdb-rhbz-2130624-assert_in_jit_event_handler.patch @@ -0,0 +1,115 @@ +From FEDORA_PATCHES Mon Sep 17 00:00:00 2001 +From: Tom de Vries +Date: Fri, 21 May 2021 15:09:14 +0200 +Subject: gdb-rhbz-2130624-assert_in_jit_event_handler.patch + +;; Backport "[gdb/breakpoint] Fix assert in jit_event_handler" +;; (Tom de Vries, RHBZ2130624) + +Consider a minimal test-case test.c: +... +int main (void) { return 0; } +... +which we can compile into llvm byte code using clang: +... +$ clang -g -S -emit-llvm --target=x86_64-unknown-unknown-elf test.c +... +and then run using lli, which uses the llvm jit: +... +$ lli test.ll +... + +If we run this under gdb, we run into an assert: +... +$ gdb -q -batch -ex run --args /usr/bin/lli test.ll +Dwarf Error: Cannot not find DIE at 0x18a936e7 \ + [from module libLLVM.so.10-10.0.1-lp152.30.4.x86_64.debug] + +[Thread debugging using libthread_db enabled] +Using host libthread_db library "/lib64/libthread_db.so.1". +src/gdb/jit.c:1178: internal-error: \ + void jit_event_handler(gdbarch*, objfile*): \ + Assertion `jiter->jiter_data != nullptr' failed. +... + +This is caused by the following. + +When running jit_breakpoint_re_set_internal, we first handle +libLLVM.so.10.debug, and set a jit breakpoint. + +Next we handle libLLVM.so.10: +... +(gdb) p the_objfile.original_name +$42 = 0x2494170 "libLLVM.so.10" +... +but the minimal symbols we find are from libLLVM.so.10.debug: +... +(gdb) p reg_symbol.objfile.original_name +$43 = 0x38e7c50 "libLLVM.so.10-10.0.1-lp152.30.4.x86_64.debug" +(gdb) p desc_symbol.objfile.original_name +$44 = 0x38e7c50 "libLLVM.so.10-10.0.1-lp152.30.4.x86_64.debug" +... +and consequently, the objf_data is the one from libLLVM.so.10.debug: +... + jiter_objfile_data *objf_data + = get_jiter_objfile_data (reg_symbol.objfile); +... +and so we hit this: +... + if (objf_data->cached_code_address == addr) + continue; +... +and no second jit breakpoint is inserted. + +Subsequently, the jit breakpoint is triggered and handled, but when finding +the symbol for the breakpoint address we get: +... +(gdb) p jit_bp_sym.objfile.original_name +$52 = 0x2494170 "libLLVM.so.10" +... + +The assert 'jiter->jiter_data != nullptr' triggers because it checks +libLLVM.so.10 while the one with jiter_data setup is libLLVM.so.10.debug. + +This fixes the assert: +... + jiter_objfile_data *objf_data +- = get_jiter_objfile_data (reg_symbol.objfile); +- = get_jiter_objfile_data (the_objfile); +... +but consequently we'll have two jit breakpoints, so we also make sure we don't +set a jit breakpoint on separate debug objects like libLLVM.so.10.debug. + +Tested on x86_64-linux. + +gdb/ChangeLog: + +2021-05-21 Tom de Vries + + PR breakpoint/27889 + * jit.c (jit_breakpoint_re_set_internal): Skip separate debug + objects. Call get_jiter_objfile_data with the_objfile. + +diff --git a/gdb/jit.c b/gdb/jit.c +--- a/gdb/jit.c ++++ b/gdb/jit.c +@@ -893,6 +893,10 @@ jit_breakpoint_re_set_internal (struct gdbarch *gdbarch, program_space *pspace) + { + for (objfile *the_objfile : pspace->objfiles ()) + { ++ /* Skip separate debug objects. */ ++ if (the_objfile->separate_debug_objfile_backlink != nullptr) ++ continue; ++ + if (the_objfile->skip_jit_symbol_lookup) + continue; + +@@ -919,7 +923,7 @@ jit_breakpoint_re_set_internal (struct gdbarch *gdbarch, program_space *pspace) + } + + jiter_objfile_data *objf_data +- = get_jiter_objfile_data (reg_symbol.objfile); ++ = get_jiter_objfile_data (the_objfile); + objf_data->register_code = reg_symbol.minsym; + objf_data->descriptor = desc_symbol.minsym; + diff --git a/gdb.spec b/gdb.spec index f97d578..ad40399 100644 --- a/gdb.spec +++ b/gdb.spec @@ -1158,6 +1158,10 @@ fi %endif %changelog +* Mon Mar 27 2023 Bruno Larsen +- Backport "[gdb/breakpoint] Fix assert in jit_event_handler" + (Tom de Vries, RHBZ 2130624) + * Wed Mar 23 2023 Bruno Larsen - Bakport "Fix assertion failure in copy_type" (Tom Tromey, RHBZ 2155439)