Saturday, September 16, 2017

GDB does not step-into functions without step-mode=on

Leave a Comment

I have an executable that is dynamically linked with a .so file, both compiled with debug symbols.

Now when I start the process with a gdb and step over it - the step command does not step into functions (defined in a .so) unless I set the step-mode on.

Sources are available and gdb certainly can find them.

Why is it happening?

Here is the corresponding debug output enabled via set debug infrun 1:

34          assert_se(calendar_spec_from_string(input, &c) >= 0); infrun: infrun_async(0) (gdb) s infrun: clear_proceed_status_thread (Thread 0x7ffff7fb3900 (LWP 7009)) infrun: proceed (addr=0xffffffffffffffff, signal=GDB_SIGNAL_DEFAULT) infrun: proceed: resuming Thread 0x7ffff7fb3900 (LWP 7009) infrun: resume (step=1, signal=GDB_SIGNAL_0), trap_expected=0, current thread [Thread 0x7ffff7fb3900 (LWP 7009)] at 0x100000e0d infrun: infrun_async(1) infrun: prepare_to_wait infrun: target_wait (-1.0.0, status) = infrun:   7009.7009.0 [Thread 0x7ffff7fb3900 (LWP 7009)], infrun:   status->kind = stopped, signal = GDB_SIGNAL_TRAP infrun: TARGET_WAITKIND_STOPPED infrun: stop_pc = 0x100000e11 infrun: stepping inside range [0x100000e0d-0x100000e4f] infrun: resume (step=1, signal=GDB_SIGNAL_0), trap_expected=0, current thread [Thread 0x7ffff7fb3900 (LWP 7009)] at 0x100000e11 infrun: prepare_to_wait infrun: target_wait (-1.0.0, status) = infrun:   7009.7009.0 [Thread 0x7ffff7fb3900 (LWP 7009)], infrun:   status->kind = stopped, signal = GDB_SIGNAL_TRAP infrun: TARGET_WAITKIND_STOPPED infrun: stop_pc = 0x100000e15 infrun: stepping inside range [0x100000e0d-0x100000e4f] infrun: resume (step=1, signal=GDB_SIGNAL_0), trap_expected=0, current thread [Thread 0x7ffff7fb3900 (LWP 7009)] at 0x100000e15 infrun: prepare_to_wait infrun: target_wait (-1.0.0, status) = infrun:   7009.7009.0 [Thread 0x7ffff7fb3900 (LWP 7009)], infrun:   status->kind = stopped, signal = GDB_SIGNAL_TRAP infrun: TARGET_WAITKIND_STOPPED infrun: stop_pc = 0x100000e18 infrun: stepping inside range [0x100000e0d-0x100000e4f] infrun: resume (step=1, signal=GDB_SIGNAL_0), trap_expected=0, current thread [Thread 0x7ffff7fb3900 (LWP 7009)] at 0x100000e18 infrun: prepare_to_wait infrun: target_wait (-1.0.0, status) = infrun:   7009.7009.0 [Thread 0x7ffff7fb3900 (LWP 7009)], infrun:   status->kind = stopped, signal = GDB_SIGNAL_TRAP infrun: TARGET_WAITKIND_STOPPED infrun: stop_pc = 0x100000e1b infrun: stepping inside range [0x100000e0d-0x100000e4f] infrun: resume (step=1, signal=GDB_SIGNAL_0), trap_expected=0, current thread [Thread 0x7ffff7fb3900 (LWP 7009)] at 0x100000e1b infrun: prepare_to_wait infrun: target_wait (-1.0.0, status) = infrun:   7009.7009.0 [Thread 0x7ffff7fb3900 (LWP 7009)], infrun:   status->kind = stopped, signal = GDB_SIGNAL_TRAP infrun: TARGET_WAITKIND_STOPPED infrun: stop_pc = 0x100000c08 infrun: stepped into subroutine infrun: inserting step-resume breakpoint at 0x100000e20 infrun: resume (step=0, signal=GDB_SIGNAL_0), trap_expected=0, current thread [Thread 0x7ffff7fb3900 (LWP 7009)] at 0x100000c08 infrun: prepare_to_wait infrun: target_wait (-1.0.0, status) = infrun:   7009.7009.0 [Thread 0x7ffff7fb3900 (LWP 7009)], infrun:   status->kind = stopped, signal = GDB_SIGNAL_TRAP infrun: TARGET_WAITKIND_STOPPED infrun: stop_pc = 0x100000e20 infrun: BPSTAT_WHAT_STEP_RESUME infrun: stepping inside range [0x100000e0d-0x100000e4f] infrun: resume (step=1, signal=GDB_SIGNAL_0), trap_expected=0, current thread [Thread 0x7ffff7fb3900 (LWP 7009)] at 0x100000e20 infrun: prepare_to_wait infrun: target_wait (-1.0.0, status) = infrun:   7009.7009.0 [Thread 0x7ffff7fb3900 (LWP 7009)], infrun:   status->kind = stopped, signal = GDB_SIGNAL_TRAP infrun: TARGET_WAITKIND_STOPPED infrun: stop_pc = 0x100000e23 infrun: stepping inside range [0x100000e0d-0x100000e4f] infrun: resume (step=1, signal=GDB_SIGNAL_0), trap_expected=0, current thread [Thread 0x7ffff7fb3900 (LWP 7009)] at 0x100000e23 infrun: prepare_to_wait infrun: target_wait (-1.0.0, status) = infrun:   7009.7009.0 [Thread 0x7ffff7fb3900 (LWP 7009)], infrun:   status->kind = stopped, signal = GDB_SIGNAL_TRAP infrun: TARGET_WAITKIND_STOPPED infrun: stop_pc = 0x100000e26 infrun: stepping inside range [0x100000e0d-0x100000e4f] infrun: resume (step=1, signal=GDB_SIGNAL_0), trap_expected=0, current thread [Thread 0x7ffff7fb3900 (LWP 7009)] at 0x100000e26 infrun: prepare_to_wait infrun: target_wait (-1.0.0, status) = infrun:   7009.7009.0 [Thread 0x7ffff7fb3900 (LWP 7009)], infrun:   status->kind = stopped, signal = GDB_SIGNAL_TRAP infrun: TARGET_WAITKIND_STOPPED infrun: stop_pc = 0x100000e29 infrun: stepping inside range [0x100000e0d-0x100000e4f] infrun: resume (step=1, signal=GDB_SIGNAL_0), trap_expected=0, current thread [Thread 0x7ffff7fb3900 (LWP 7009)] at 0x100000e29 infrun: prepare_to_wait infrun: target_wait (-1.0.0, status) = infrun:   7009.7009.0 [Thread 0x7ffff7fb3900 (LWP 7009)], infrun:   status->kind = stopped, signal = GDB_SIGNAL_TRAP infrun: TARGET_WAITKIND_STOPPED infrun: stop_pc = 0x100000e4f infrun: stepped to a different line infrun: stop_waiting infrun: clear_step_over_info infrun: stop_all_threads infrun: stop_all_threads, pass=0, iterations=0 infrun:   Thread 0x7ffff7fb3900 (LWP 7009) not executing infrun: stop_all_threads, pass=1, iterations=1 infrun:   Thread 0x7ffff7fb3900 (LWP 7009) not executing infrun: stop_all_threads done 36          assert_se(calendar_spec_to_string(c, &p) >= 0); infrun: infrun_async(0) (gdb) s infrun: clear_proceed_status_thread (Thread 0x7ffff7fb3900 (LWP 7009)) infrun: proceed (addr=0xffffffffffffffff, signal=GDB_SIGNAL_DEFAULT) infrun: proceed: resuming Thread 0x7ffff7fb3900 (LWP 7009) infrun: resume (step=1, signal=GDB_SIGNAL_0), trap_expected=0, current thread [Thread 0x7ffff7fb3900 (LWP 7009)] at 0x100000e4f infrun: infrun_async(1) infrun: prepare_to_wait infrun: target_wait (-1.0.0, status) = infrun:   7009.7009.0 [Thread 0x7ffff7fb3900 (LWP 7009)], infrun:   status->kind = stopped, signal = GDB_SIGNAL_TRAP infrun: TARGET_WAITKIND_STOPPED infrun: stop_pc = 0x100000e53 infrun: stepping inside range [0x100000e4f-0x100000e91] infrun: resume (step=1, signal=GDB_SIGNAL_0), trap_expected=0, current thread [Thread 0x7ffff7fb3900 (LWP 7009)] at 0x100000e53 infrun: prepare_to_wait infrun: target_wait (-1.0.0, status) = infrun:   -1.0.0 [process -1], infrun:   status->kind = ignore infrun: TARGET_WAITKIND_IGNORE infrun: prepare_to_wait infrun: target_wait (-1.0.0, status) = infrun:   7009.7009.0 [Thread 0x7ffff7fb3900 (LWP 7009)], infrun:   status->kind = stopped, signal = GDB_SIGNAL_TRAP infrun: TARGET_WAITKIND_STOPPED infrun: stop_pc = 0x100000e57 infrun: stepping inside range [0x100000e4f-0x100000e91] infrun: resume (step=1, signal=GDB_SIGNAL_0), trap_expected=0, current thread [Thread 0x7ffff7fb3900 (LWP 7009)] at 0x100000e57 infrun: prepare_to_wait infrun: target_wait (-1.0.0, status) = infrun:   -1.0.0 [process -1], infrun:   status->kind = ignore infrun: TARGET_WAITKIND_IGNORE infrun: prepare_to_wait infrun: target_wait (-1.0.0, status) = infrun:   7009.7009.0 [Thread 0x7ffff7fb3900 (LWP 7009)], infrun:   status->kind = stopped, signal = GDB_SIGNAL_TRAP infrun: TARGET_WAITKIND_STOPPED infrun: stop_pc = 0x100000e5a infrun: stepping inside range [0x100000e4f-0x100000e91] infrun: resume (step=1, signal=GDB_SIGNAL_0), trap_expected=0, current thread [Thread 0x7ffff7fb3900 (LWP 7009)] at 0x100000e5a infrun: prepare_to_wait infrun: target_wait (-1.0.0, status) = infrun:   -1.0.0 [process -1], infrun:   status->kind = ignore infrun: TARGET_WAITKIND_IGNORE infrun: prepare_to_wait infrun: target_wait (-1.0.0, status) = infrun:   7009.7009.0 [Thread 0x7ffff7fb3900 (LWP 7009)], infrun:   status->kind = stopped, signal = GDB_SIGNAL_TRAP infrun: TARGET_WAITKIND_STOPPED infrun: stop_pc = 0x100000e5d infrun: stepping inside range [0x100000e4f-0x100000e91] infrun: resume (step=1, signal=GDB_SIGNAL_0), trap_expected=0, current thread [Thread 0x7ffff7fb3900 (LWP 7009)] at 0x100000e5d infrun: prepare_to_wait infrun: target_wait (-1.0.0, status) = infrun:   -1.0.0 [process -1], infrun:   status->kind = ignore infrun: TARGET_WAITKIND_IGNORE infrun: prepare_to_wait infrun: target_wait (-1.0.0, status) = infrun:   7009.7009.0 [Thread 0x7ffff7fb3900 (LWP 7009)], infrun:   status->kind = stopped, signal = GDB_SIGNAL_TRAP infrun: TARGET_WAITKIND_STOPPED infrun: stop_pc = 0x100000c48 infrun: stepped into subroutine infrun: inserting step-resume breakpoint at 0x100000e62 infrun: resume (step=0, signal=GDB_SIGNAL_0), trap_expected=0, current thread [Thread 0x7ffff7fb3900 (LWP 7009)] at 0x100000c48 infrun: prepare_to_wait infrun: target_wait (-1.0.0, status) = infrun:   -1.0.0 [process -1], infrun:   status->kind = ignore infrun: TARGET_WAITKIND_IGNORE infrun: prepare_to_wait infrun: target_wait (-1.0.0, status) = infrun:   7009.7009.0 [Thread 0x7ffff7fb3900 (LWP 7009)], infrun:   status->kind = stopped, signal = GDB_SIGNAL_TRAP infrun: TARGET_WAITKIND_STOPPED infrun: stop_pc = 0x100000e62 infrun: BPSTAT_WHAT_STEP_RESUME infrun: stepping inside range [0x100000e4f-0x100000e91] infrun: resume (step=1, signal=GDB_SIGNAL_0), trap_expected=0, current thread [Thread 0x7ffff7fb3900 (LWP 7009)] at 0x100000e62 infrun: prepare_to_wait infrun: target_wait (-1.0.0, status) = infrun:   -1.0.0 [process -1], infrun:   status->kind = ignore infrun: TARGET_WAITKIND_IGNORE infrun: prepare_to_wait infrun: target_wait (-1.0.0, status) = infrun:   7009.7009.0 [Thread 0x7ffff7fb3900 (LWP 7009)], infrun:   status->kind = stopped, signal = GDB_SIGNAL_TRAP infrun: TARGET_WAITKIND_STOPPED infrun: stop_pc = 0x100000e65 infrun: stepping inside range [0x100000e4f-0x100000e91] infrun: resume (step=1, signal=GDB_SIGNAL_0), trap_expected=0, current thread [Thread 0x7ffff7fb3900 (LWP 7009)] at 0x100000e65 infrun: prepare_to_wait infrun: target_wait (-1.0.0, status) = infrun:   -1.0.0 [process -1], infrun:   status->kind = ignore infrun: TARGET_WAITKIND_IGNORE infrun: prepare_to_wait infrun: target_wait (-1.0.0, status) = infrun:   7009.7009.0 [Thread 0x7ffff7fb3900 (LWP 7009)], infrun:   status->kind = stopped, signal = GDB_SIGNAL_TRAP infrun: TARGET_WAITKIND_STOPPED infrun: stop_pc = 0x100000e68 infrun: stepping inside range [0x100000e4f-0x100000e91] infrun: resume (step=1, signal=GDB_SIGNAL_0), trap_expected=0, current thread [Thread 0x7ffff7fb3900 (LWP 7009)] at 0x100000e68 infrun: prepare_to_wait infrun: target_wait (-1.0.0, status) = infrun:   7009.7009.0 [Thread 0x7ffff7fb3900 (LWP 7009)], infrun:   status->kind = stopped, signal = GDB_SIGNAL_TRAP infrun: TARGET_WAITKIND_STOPPED infrun: stop_pc = 0x100000e6b infrun: stepping inside range [0x100000e4f-0x100000e91] infrun: resume (step=1, signal=GDB_SIGNAL_0), trap_expected=0, current thread [Thread 0x7ffff7fb3900 (LWP 7009)] at 0x100000e6b infrun: prepare_to_wait infrun: target_wait (-1.0.0, status) = infrun:   -1.0.0 [process -1], infrun:   status->kind = ignore infrun: TARGET_WAITKIND_IGNORE infrun: prepare_to_wait infrun: target_wait (-1.0.0, status) = infrun:   7009.7009.0 [Thread 0x7ffff7fb3900 (LWP 7009)], infrun:   status->kind = stopped, signal = GDB_SIGNAL_TRAP infrun: TARGET_WAITKIND_STOPPED infrun: stop_pc = 0x100000e91 infrun: stepped to a different line infrun: stop_waiting infrun: clear_step_over_info infrun: stop_all_threads infrun: stop_all_threads, pass=0, iterations=0 infrun:   Thread 0x7ffff7fb3900 (LWP 7009) not executing infrun: stop_all_threads, pass=1, iterations=1 infrun:   Thread 0x7ffff7fb3900 (LWP 7009) not executing infrun: stop_all_threads done 37          printf("\"%s\" → \"%s\"\n", input, p); infrun: infrun_async(0) 

1 Answers

Answers 1

Seems to be related to "-Wl,-z,now" option to the linker.

man page says:

now - When generating an executable or shared library, mark it to tell the dynamic linker to resolve all symbols when the program is started, or when the shared library is linked to using dlopen, instead of deferring function call resolution to the point when the function is first called.

When you set step-mode on and gebug an executable linked with this option, you may notice that you don't step directly to the function in the shared library, but at first to somewhere like

(gdb) s 0x0000555555554638 in ?? () 

Can't say exactly, what it is.

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment