Skip to content

Commit bafcc33

Browse files
committed
Fix stepping in rtld without debug symbol
Commit be6276e "Allow debugging of runtime loader / dynamic linker" introduced a small regression when stepping into the runtime loader / dynamic linker from function we do not have debug information for. This is reported in PR/29747. This can be shown by the following example (given by Simon Marchi in buzilla bug report): $ cat test.c #include <stdio.h> int main() { printf("Hi\n"); return 0; } $ gcc test.c -O0 -o test $ ./gdb -q -nx --data-directory=data-directory test -ex start -ex s Reading symbols from test... (No debugging symbols found in test) Temporary breakpoint 1 at 0x1151 Starting program: .../binutils-gdb/gdb/test [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". Temporary breakpoint 1, 0x0000555555555151 in main () Single stepping until exit from function main, which has no line number information. /home/smarchi/src/binutils-gdb/gdb/infrun.c:6960:64: runtime error: member call on null pointer of type 'struct symbol' The crash happens here: #0 __sanitizer::Die () at ../../../../src/libsanitizer/sanitizer_common/sanitizer_termination.cpp:50 #1 0x00007ffff5dd7128 in __ubsan::__ubsan_handle_type_mismatch_v1_abort (Data=<optimized out>, Pointer=<optimized out>) at ../../../../src/libsanitizer/ubsan/ubsan_handlers.cpp:148 #2 0x000055556183e1a7 in process_event_stop_test (ecs=0x7fffffffccd0) at .../binutils-gdb/gdb/infrun.c:6960 #3 0x0000555561838ea4 in handle_signal_stop (ecs=0x7fffffffccd0) at .../binutils-gdb/gdb/infrun.c:6615 bminor#4 0x000055556182f77b in handle_inferior_event (ecs=0x7fffffffccd0) at .../binutils-gdb/gdb/infrun.c:5866 When evaluating: 6956 if (execution_direction != EXEC_REVERSE 6957 && ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE 6958 && in_solib_dynsym_resolve_code (ecs->event_thread->stop_pc ()) 6959 && !in_solib_dynsym_resolve_code ( 6961 ecs->event_thread->control.step_start_function->value_block () 6962 ->entry_pc ())) we dereference, ecs->event_thread->control.step_start_function which is nullptr. This patch changes this condition so it evaluates to true if ecs->event_thread->control.step_start_function is nullptr since this matches the behaviour before be6276e. Tested on ubuntu-22.04 x86_64. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29747 Reviewed-By: Bruno Larsen <blarsen@redhat.com> Approved-By: Kevin Buettner <kevinb@redhat.com>
1 parent 3abad2f commit bafcc33

File tree

3 files changed

+61
-3
lines changed

3 files changed

+61
-3
lines changed

gdb/infrun.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6956,9 +6956,10 @@ process_event_stop_test (struct execution_control_state *ecs)
69566956
if (execution_direction != EXEC_REVERSE
69576957
&& ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE
69586958
&& in_solib_dynsym_resolve_code (ecs->event_thread->stop_pc ())
6959-
&& !in_solib_dynsym_resolve_code (
6960-
ecs->event_thread->control.step_start_function->value_block ()
6961-
->entry_pc ()))
6959+
&& (ecs->event_thread->control.step_start_function == nullptr
6960+
|| !in_solib_dynsym_resolve_code (
6961+
ecs->event_thread->control.step_start_function->value_block ()
6962+
->entry_pc ())))
69626963
{
69636964
CORE_ADDR pc_after_resolver =
69646965
gdbarch_skip_solib_resolver (gdbarch, ecs->event_thread->stop_pc ());
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/* This testcase is part of GDB, the GNU debugger.
2+
3+
Copyright 2022 Free Software Foundation, Inc.
4+
5+
This program is free software; you can redistribute it and/or modify
6+
it under the terms of the GNU General Public License as published by
7+
the Free Software Foundation; either version 3 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU General Public License for more details.
14+
15+
You should have received a copy of the GNU General Public License
16+
along with this program. If not, see <http://www.gnu.org/licenses/>. */
17+
18+
#include <stdio.h>
19+
20+
int
21+
main (void)
22+
{
23+
printf ("hello world");
24+
return 0;
25+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Copyright 2022 Free Software Foundation, Inc.
2+
3+
# This program is free software; you can redistribute it and/or modify
4+
# it under the terms of the GNU General Public License as published by
5+
# the Free Software Foundation; either version 3 of the License, or
6+
# (at your option) any later version.
7+
#
8+
# This program is distributed in the hope that it will be useful,
9+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
# GNU General Public License for more details.
12+
#
13+
# You should have received a copy of the GNU General Public License
14+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
15+
16+
# Test stepping through a runtime loader / dynamic linker (RTLD) without
17+
# debug info.
18+
19+
standard_testfile
20+
21+
if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} \
22+
{nodebug}] } {
23+
return
24+
}
25+
26+
if { ![runto_main] } {
27+
return
28+
}
29+
30+
gdb_test "step" "Single stepping until exit from function.*"
31+
32+
gdb_continue_to_end "" continue 1

0 commit comments

Comments
 (0)