* [PATCH][gdb/breakpoint] Fix stepping past non-stmt line-table entries
@ 2021-01-14 13:26 Tom de Vries
2021-01-23 8:07 ` Bernd Edlinger
0 siblings, 1 reply; 3+ messages in thread
From: Tom de Vries @ 2021-01-14 13:26 UTC (permalink / raw)
To: gdb-patches
Hi,
Consider the test-case small.c:
...
$ cat -n small.c
1 __attribute__ ((noinline, noclone))
2 int foo (char *c)
3 {
4 asm volatile ("" : : "r" (c) : "memory");
5 return 1;
6 }
7
8 int main ()
9 {
10 char tpl1[20] = "/tmp/test.XXX";
11 char tpl2[20] = "/tmp/test.XXX";
12 int fd1 = foo (tpl1);
13 int fd2 = foo (tpl2);
14 if (fd1 == -1) {
15 return 1;
16 }
17
18 return 0;
19 }
...
Compiled with gcc-8 and optimization:
...
$ gcc-8 -O2 -g small.c
...
We step through the calls to foo, but fail to visit line 13:
...
12 int fd1 = foo (tpl1);
(gdb) step
foo (c=c@entry=0x7fffffffdea0 "/tmp/test.XXX") at small.c:5
5 return 1;
(gdb) step
foo (c=c@entry=0x7fffffffdec0 "/tmp/test.XXX") at small.c:5
5 return 1;
(gdb) step
main () at small.c:14
14 if (fd1 == -1) {
(gdb)
...
This is caused by the following. The calls to foo are implemented by these
insns:
....
4003df: 0f 29 04 24 movaps %xmm0,(%rsp)
4003e3: 0f 29 44 24 20 movaps %xmm0,0x20(%rsp)
4003e8: e8 03 01 00 00 callq 4004f0 <foo>
4003ed: 48 8d 7c 24 20 lea 0x20(%rsp),%rdi
4003f2: 89 c2 mov %eax,%edx
4003f4: e8 f7 00 00 00 callq 4004f0 <foo>
4003f9: 31 c0 xor %eax,%eax
...
with corresponding line table entries:
...
INDEX LINE ADDRESS IS-STMT
8 12 0x00000000004003df Y
9 10 0x00000000004003df
10 11 0x00000000004003e3
11 12 0x00000000004003e8
12 13 0x00000000004003ed
13 12 0x00000000004003f2
14 13 0x00000000004003f4 Y
15 13 0x00000000004003f4
16 14 0x00000000004003f9 Y
17 14 0x00000000004003f9
...
Once we step out of the call to foo at 4003e8, we land at 4003ed, and gdb
enters process_event_stop_test to figure out what to do.
That entry has is-stmt=n, so it's not the start of a line, so we don't stop
there. However, we do update ecs->event_thread->current_line to line 13,
because the frame has changed (because we stepped out of the function).
Next we land at 4003f2. Again the entry has is-stmt=n, so it's not the start
of a line, so we don't stop there. However, because the frame hasn't changed,
we don't update update ecs->event_thread->current_line, so it stays 13.
Next we land at 4003f4. Now is-stmt=y, so it's the start of a line, and we'd
like to stop here.
But we don't stop because this test fails:
...
if ((ecs->event_thread->suspend.stop_pc == stop_pc_sal.pc)
&& (ecs->event_thread->current_line != stop_pc_sal.line
|| ecs->event_thread->current_symtab != stop_pc_sal.symtab))
{
...
because ecs->event_thread->current_line == 13 and stop_pc_sal.line == 13.
Fix this by resetting ecs->event_thread->current_line to 0 if is-stmt=n and
the frame has changed, such that we have:
...
12 int fd1 = foo (tpl1);
(gdb) step
foo (c=c@entry=0x7fffffffdbc0 "/tmp/test.XXX") at small.c:5
5 return 1;
(gdb) step
main () at small.c:13
13 int fd2 = foo (tpl2);
(gdb)
...
Tested on x86_64-linux, with gcc-7 and gcc-8.
Any comments?
Thanks,
- Tom
[gdb/breakpoint] Fix stepping past non-stmt line-table entries
gdb/ChangeLog:
2021-01-14 Tom de Vries <tdevries@suse.de>
PR breakpoints/26063
* infrun.c (process_event_stop_test): Reset
ecs->event_thread->current_line to 0 if is-stmt=n and frame has
changed.
gdb/testsuite/ChangeLog:
2021-01-14 Tom de Vries <tdevries@suse.de>
PR breakpoints/26063
* gdb.dwarf2/dw2-step-out-of-function-no-stmt.c: New test.
* gdb.dwarf2/dw2-step-out-of-function-no-stmt.exp: New file.
---
gdb/infrun.c | 29 +++--
.../gdb.dwarf2/dw2-step-out-of-function-no-stmt.c | 44 +++++++
.../dw2-step-out-of-function-no-stmt.exp | 126 +++++++++++++++++++++
3 files changed, 192 insertions(+), 7 deletions(-)
diff --git a/gdb/infrun.c b/gdb/infrun.c
index 940f575e22a..57a70b5aa96 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -7000,12 +7000,15 @@ process_event_stop_test (struct execution_control_state *ecs)
&& (ecs->event_thread->current_line != stop_pc_sal.line
|| ecs->event_thread->current_symtab != stop_pc_sal.symtab))
{
+ /* We are at a different line. */
+
if (stop_pc_sal.is_stmt)
{
- /* We are at the start of a different line. So stop. Note that
- we don't stop if we step into the middle of a different line.
- That is said to make things like for (;;) statements work
- better. */
+ /* We are at the start of a statement.
+
+ So stop. Note that we don't stop if we step into the middle of a
+ statement. That is said to make things like for (;;) statements
+ work better. */
infrun_debug_printf ("stepped to a different line");
end_stepping_range (ecs);
return;
@@ -7013,14 +7016,26 @@ process_event_stop_test (struct execution_control_state *ecs)
else if (frame_id_eq (get_frame_id (get_current_frame ()),
ecs->event_thread->control.step_frame_id))
{
- /* We are at the start of a different line, however, this line is
- not marked as a statement, and we have not changed frame. We
- ignore this line table entry, and continue stepping forward,
+ /* We are not at the start of a statement, and we have not changed
+ frame.
+
+ We ignore this line table entry, and continue stepping forward,
looking for a better place to stop. */
refresh_step_info = false;
infrun_debug_printf ("stepped to a different line, but "
"it's not the start of a statement");
}
+ else
+ {
+ /* We are not the start of a statement, and we have changed frame.
+
+ We ignore this line table entry, and continue stepping forward,
+ looking for a better place to stop. Keep refresh_step_info at
+ true to note that the frame has changed, but ignore the line
+ number to make sure we don't ignore a subsequent entry with the
+ same line number. */
+ stop_pc_sal.line = 0;
+ }
}
/* We aren't done stepping.
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-step-out-of-function-no-stmt.c b/gdb/testsuite/gdb.dwarf2/dw2-step-out-of-function-no-stmt.c
new file mode 100644
index 00000000000..a8184f0c1bb
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/dw2-step-out-of-function-no-stmt.c
@@ -0,0 +1,44 @@
+/*
+ Copyright 2021 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+void
+foo (int x)
+{
+
+}
+
+void
+bar (void)
+{
+ asm ("bar_label: .globl bar_label");
+}
+
+int
+main (void)
+{
+ asm ("main_label: .globl main_label");
+
+ bar ();
+
+ asm ("main_label_2: .globl main_label_2");
+
+ foo (10);
+
+ asm ("main_label_3: .globl main_label_3");
+
+ return 0;
+}
+
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-step-out-of-function-no-stmt.exp b/gdb/testsuite/gdb.dwarf2/dw2-step-out-of-function-no-stmt.exp
new file mode 100644
index 00000000000..9249eb590f7
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/dw2-step-out-of-function-no-stmt.exp
@@ -0,0 +1,126 @@
+# Copyright 2021 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Check whether stepping out of a function works, in case:
+# - the first insn after the call has an is-stmt=no entry
+# - the next insn has an is-stmt=yes entry, for the same line number
+#
+# This sort of thing can occur in optimized code, f.i. here a slightly more
+# elaborate case with another is-stmt=no entry (the one with line number 12)
+# inbetween:
+# INDEX LINE ADDRESS IS-STMT
+# 12 13 0x00000000004003ed
+# 13 12 0x00000000004003f2
+# 14 13 0x00000000004003f4 Y
+
+load_lib dwarf.exp
+
+# This test can only be run on targets which support DWARF-2 and use gas.
+if {![dwarf2_support]} {
+ verbose "Skipping $gdb_test_file_name."
+ return 0
+}
+
+# The .c files use __attribute__.
+if [get_compiler_info] {
+ return -1
+}
+if !$gcc_compiled {
+ verbose "Skipping $gdb_test_file_name."
+ return 0
+}
+
+standard_testfile .c -dw.S
+
+set asm_file [standard_output_file $srcfile2]
+Dwarf::assemble $asm_file {
+ declare_labels Llines
+ global srcdir subdir srcfile
+
+ lassign [function_range main [list ${srcdir}/${subdir}/$srcfile]] \
+ main_start main_len
+ set main_end "$main_start + $main_len"
+
+ lassign [function_range main [list ${srcdir}/${subdir}/$srcfile]] \
+ bar_start bar_len
+ set bar_end "$bar_start + $bar_len"
+
+ cu {} {
+ compile_unit {
+ {language @DW_LANG_C}
+ {name $srcfile}
+ {stmt_list $Llines DW_FORM_sec_offset}
+ } {
+ subprogram {
+ {external 1 flag}
+ {MACRO_AT_func {main}}
+ }
+ subprogram {
+ {external 1 flag}
+ {MACRO_AT_func {bar}}
+ }
+ }
+ }
+
+ lines {version 2} Llines {
+ include_dir "${srcdir}/${subdir}"
+ file_name "$srcfile" 1
+
+ program {
+ {DW_LNE_set_address bar_label}
+ {line 26}
+ {DW_LNS_copy}
+
+ {DW_LNE_set_address $bar_end}
+ {DW_LNE_end_sequence}
+
+ {DW_LNE_set_address main_label}
+ {line 32}
+ {DW_LNS_copy}
+
+ {DW_LNE_set_address main_label_2}
+ {line 36}
+ {DW_LNS_negate_stmt}
+ {DW_LNS_copy}
+ {DW_LNS_negate_stmt}
+
+ {DW_LNE_set_address main_label_3}
+ {line 36}
+ {DW_LNS_copy}
+
+ {DW_LNE_set_address $main_end}
+ {DW_LNE_end_sequence}
+ }
+ }
+}
+
+if { [prepare_for_testing "failed to prepare" ${testfile} \
+ [list $srcfile $asm_file] {nodebug}] } {
+ return -1
+}
+
+if ![runto_main] {
+ return -1
+}
+
+# Step into bar.
+gdb_breakpoint "bar"
+gdb_continue_to_breakpoint "bar"
+
+# Step out of bar.
+gdb_test "step" [multi_line \
+ "main \\(\\) at \[^\r\n\]*$srcfile:36" \
+ "36\t\[^\r\n\]*"]
+
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH][gdb/breakpoint] Fix stepping past non-stmt line-table entries
2021-01-14 13:26 [PATCH][gdb/breakpoint] Fix stepping past non-stmt line-table entries Tom de Vries
@ 2021-01-23 8:07 ` Bernd Edlinger
2021-01-29 10:23 ` Tom de Vries
0 siblings, 1 reply; 3+ messages in thread
From: Bernd Edlinger @ 2021-01-23 8:07 UTC (permalink / raw)
To: Tom de Vries, gdb-patches
On 1/14/21 2:26 PM, Tom de Vries wrote:
> Hi,
>
> Consider the test-case small.c:
> ...
> $ cat -n small.c
> 1 __attribute__ ((noinline, noclone))
> 2 int foo (char *c)
> 3 {
> 4 asm volatile ("" : : "r" (c) : "memory");
> 5 return 1;
> 6 }
> 7
> 8 int main ()
> 9 {
> 10 char tpl1[20] = "/tmp/test.XXX";
> 11 char tpl2[20] = "/tmp/test.XXX";
> 12 int fd1 = foo (tpl1);
> 13 int fd2 = foo (tpl2);
> 14 if (fd1 == -1) {
> 15 return 1;
> 16 }
> 17
> 18 return 0;
> 19 }
> ...
>
> Compiled with gcc-8 and optimization:
> ...
> $ gcc-8 -O2 -g small.c
> ...
>
> We step through the calls to foo, but fail to visit line 13:
> ...
> 12 int fd1 = foo (tpl1);
> (gdb) step
> foo (c=c@entry=0x7fffffffdea0 "/tmp/test.XXX") at small.c:5
> 5 return 1;
> (gdb) step
> foo (c=c@entry=0x7fffffffdec0 "/tmp/test.XXX") at small.c:5
> 5 return 1;
> (gdb) step
> main () at small.c:14
> 14 if (fd1 == -1) {
> (gdb)
> ...
>
> This is caused by the following. The calls to foo are implemented by these
> insns:
> ....
> 4003df: 0f 29 04 24 movaps %xmm0,(%rsp)
> 4003e3: 0f 29 44 24 20 movaps %xmm0,0x20(%rsp)
> 4003e8: e8 03 01 00 00 callq 4004f0 <foo>
> 4003ed: 48 8d 7c 24 20 lea 0x20(%rsp),%rdi
> 4003f2: 89 c2 mov %eax,%edx
> 4003f4: e8 f7 00 00 00 callq 4004f0 <foo>
> 4003f9: 31 c0 xor %eax,%eax
> ...
> with corresponding line table entries:
> ...
> INDEX LINE ADDRESS IS-STMT
> 8 12 0x00000000004003df Y
> 9 10 0x00000000004003df
> 10 11 0x00000000004003e3
> 11 12 0x00000000004003e8
> 12 13 0x00000000004003ed
> 13 12 0x00000000004003f2
> 14 13 0x00000000004003f4 Y
> 15 13 0x00000000004003f4
> 16 14 0x00000000004003f9 Y
> 17 14 0x00000000004003f9
> ...
>
> Once we step out of the call to foo at 4003e8, we land at 4003ed, and gdb
> enters process_event_stop_test to figure out what to do.
>
> That entry has is-stmt=n, so it's not the start of a line, so we don't stop
> there. However, we do update ecs->event_thread->current_line to line 13,
> because the frame has changed (because we stepped out of the function).
>
> Next we land at 4003f2. Again the entry has is-stmt=n, so it's not the start
> of a line, so we don't stop there. However, because the frame hasn't changed,
> we don't update update ecs->event_thread->current_line, so it stays 13.
>
> Next we land at 4003f4. Now is-stmt=y, so it's the start of a line, and we'd
> like to stop here.
>
> But we don't stop because this test fails:
> ...
> if ((ecs->event_thread->suspend.stop_pc == stop_pc_sal.pc)
> && (ecs->event_thread->current_line != stop_pc_sal.line
> || ecs->event_thread->current_symtab != stop_pc_sal.symtab))
> {
> ...
> because ecs->event_thread->current_line == 13 and stop_pc_sal.line == 13.
>
> Fix this by resetting ecs->event_thread->current_line to 0 if is-stmt=n and
> the frame has changed, such that we have:
> ...
> 12 int fd1 = foo (tpl1);
> (gdb) step
> foo (c=c@entry=0x7fffffffdbc0 "/tmp/test.XXX") at small.c:5
> 5 return 1;
> (gdb) step
> main () at small.c:13
> 13 int fd2 = foo (tpl2);
> (gdb)
> ...
>
> Tested on x86_64-linux, with gcc-7 and gcc-8.
>
> Any comments?
>
I agree that this should be fixed.
It is interesting that the small.c example does not miss to
step at line 13 if I manually add a nop after the call foo.
In this case we are still at line 12, where the call is coming
from.
I think when we step away from the call instruction we should
use the line info from the call statement which is 12 in this
example, not the non-stmt line immediately after the call
stmt which is 13.
find_pc_line can be used to find the line immediately before
the current pc when the second parameter is non-zero.
So how about this:
diff --git a/gdb/infrun.c b/gdb/infrun.c
index 7bbfe04..c823586 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -7048,6 +7048,19 @@ struct wait_one_event
infrun_debug_printf ("stepped to a different line, but "
"it's not the start of a statement");
}
+ else
+ {
+ struct symtab_and_line call_line;
+
+ /* We are returning from a call immediatley before the stop_pc.
+ Therefore we are stepping away from the call line. */
+ call_line = find_pc_line (ecs->event_thread->suspend.stop_pc, 1);
+ if (call_line.line != 0)
+ {
+ stop_pc_sal.line = call_line.line;
+ stop_pc_sal.symtab = call_line.symtab;
+ }
+ }
}
/* We aren't done stepping.
Bernd.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH][gdb/breakpoint] Fix stepping past non-stmt line-table entries
2021-01-23 8:07 ` Bernd Edlinger
@ 2021-01-29 10:23 ` Tom de Vries
0 siblings, 0 replies; 3+ messages in thread
From: Tom de Vries @ 2021-01-29 10:23 UTC (permalink / raw)
To: Bernd Edlinger, gdb-patches
On 1/23/21 9:07 AM, Bernd Edlinger wrote:
> On 1/14/21 2:26 PM, Tom de Vries wrote:
>> Hi,
>>
>> Consider the test-case small.c:
>> ...
>> $ cat -n small.c
>> 1 __attribute__ ((noinline, noclone))
>> 2 int foo (char *c)
>> 3 {
>> 4 asm volatile ("" : : "r" (c) : "memory");
>> 5 return 1;
>> 6 }
>> 7
>> 8 int main ()
>> 9 {
>> 10 char tpl1[20] = "/tmp/test.XXX";
>> 11 char tpl2[20] = "/tmp/test.XXX";
>> 12 int fd1 = foo (tpl1);
>> 13 int fd2 = foo (tpl2);
>> 14 if (fd1 == -1) {
>> 15 return 1;
>> 16 }
>> 17
>> 18 return 0;
>> 19 }
>> ...
>>
>> Compiled with gcc-8 and optimization:
>> ...
>> $ gcc-8 -O2 -g small.c
>> ...
>>
>> We step through the calls to foo, but fail to visit line 13:
>> ...
>> 12 int fd1 = foo (tpl1);
>> (gdb) step
>> foo (c=c@entry=0x7fffffffdea0 "/tmp/test.XXX") at small.c:5
>> 5 return 1;
>> (gdb) step
>> foo (c=c@entry=0x7fffffffdec0 "/tmp/test.XXX") at small.c:5
>> 5 return 1;
>> (gdb) step
>> main () at small.c:14
>> 14 if (fd1 == -1) {
>> (gdb)
>> ...
>>
>> This is caused by the following. The calls to foo are implemented by these
>> insns:
>> ....
>> 4003df: 0f 29 04 24 movaps %xmm0,(%rsp)
>> 4003e3: 0f 29 44 24 20 movaps %xmm0,0x20(%rsp)
>> 4003e8: e8 03 01 00 00 callq 4004f0 <foo>
>> 4003ed: 48 8d 7c 24 20 lea 0x20(%rsp),%rdi
>> 4003f2: 89 c2 mov %eax,%edx
>> 4003f4: e8 f7 00 00 00 callq 4004f0 <foo>
>> 4003f9: 31 c0 xor %eax,%eax
>> ...
>> with corresponding line table entries:
>> ...
>> INDEX LINE ADDRESS IS-STMT
>> 8 12 0x00000000004003df Y
>> 9 10 0x00000000004003df
>> 10 11 0x00000000004003e3
>> 11 12 0x00000000004003e8
>> 12 13 0x00000000004003ed
>> 13 12 0x00000000004003f2
>> 14 13 0x00000000004003f4 Y
>> 15 13 0x00000000004003f4
>> 16 14 0x00000000004003f9 Y
>> 17 14 0x00000000004003f9
>> ...
>>
>> Once we step out of the call to foo at 4003e8, we land at 4003ed, and gdb
>> enters process_event_stop_test to figure out what to do.
>>
>> That entry has is-stmt=n, so it's not the start of a line, so we don't stop
>> there. However, we do update ecs->event_thread->current_line to line 13,
>> because the frame has changed (because we stepped out of the function).
>>
>> Next we land at 4003f2. Again the entry has is-stmt=n, so it's not the start
>> of a line, so we don't stop there. However, because the frame hasn't changed,
>> we don't update update ecs->event_thread->current_line, so it stays 13.
>>
>> Next we land at 4003f4. Now is-stmt=y, so it's the start of a line, and we'd
>> like to stop here.
>>
>> But we don't stop because this test fails:
>> ...
>> if ((ecs->event_thread->suspend.stop_pc == stop_pc_sal.pc)
>> && (ecs->event_thread->current_line != stop_pc_sal.line
>> || ecs->event_thread->current_symtab != stop_pc_sal.symtab))
>> {
>> ...
>> because ecs->event_thread->current_line == 13 and stop_pc_sal.line == 13.
>>
>> Fix this by resetting ecs->event_thread->current_line to 0 if is-stmt=n and
>> the frame has changed, such that we have:
>> ...
>> 12 int fd1 = foo (tpl1);
>> (gdb) step
>> foo (c=c@entry=0x7fffffffdbc0 "/tmp/test.XXX") at small.c:5
>> 5 return 1;
>> (gdb) step
>> main () at small.c:13
>> 13 int fd2 = foo (tpl2);
>> (gdb)
>> ...
>>
>> Tested on x86_64-linux, with gcc-7 and gcc-8.
>>
>> Any comments?
>>
>
> I agree that this should be fixed.
>
Hi Bernd,
thanks for the review.
> It is interesting that the small.c example does not miss to
> step at line 13 if I manually add a nop after the call foo.
> In this case we are still at line 12, where the call is coming
> from.
>
I can reproduce that like so:
...
call foo
+ nop
.LVL1:
.loc 1 13 13 view .LVU15
leaq 32(%rsp), %rdi
.loc 1 12 13 view .LVU16
movl %eax, %edx
.LVL2:
.loc 1 13 3 is_stmt 1 view .LVU17
.loc 1 13 13 is_stmt 0 view .LVU18
call foo
...
resulting in:
...
4003d7: 0f 29 04 24 movaps %xmm0,(%rsp)
4003db: 0f 29 44 24 20 movaps %xmm0,0x20(%rsp)
4003e0: c7 44 24 30 00 00 00 movl $0x0,0x30(%rsp)
4003e7: 00
4003e8: e8 03 01 00 00 callq 4004f0 <foo>
4003ed: 90 nop
4003ee: 48 8d 7c 24 20 lea 0x20(%rsp),%rdi
4003f3: 89 c2 mov %eax,%edx
4003f5: e8 f6 00 00 00 callq 4004f0 <foo>
4003fa: 31 c0 xor %eax,%eax
...
So, once we step out of the call to foo at 4003e8, we land at the nop at
4003ed, and gdb enters process_event_stop_test to figure out what to do.
Since there's no line number entry at that address, we get:
...
(gdb) p stop_pc_sal.line
$7 = 12
...
instead of line 13, which causes the stepping to stop at the subsequent
is-stmt=y entry at line 13.
> I think when we step away from the call instruction we should
> use the line info from the call statement which is 12 in this
> example, not the non-stmt line immediately after the call
> stmt which is 13.
>
> find_pc_line can be used to find the line immediately before
> the current pc when the second parameter is non-zero.
>
> So how about this:
>
> diff --git a/gdb/infrun.c b/gdb/infrun.c
> index 7bbfe04..c823586 100644
> --- a/gdb/infrun.c
> +++ b/gdb/infrun.c
> @@ -7048,6 +7048,19 @@ struct wait_one_event
> infrun_debug_printf ("stepped to a different line, but "
> "it's not the start of a statement");
> }
> + else
> + {
> + struct symtab_and_line call_line;
> +
> + /* We are returning from a call immediatley before the stop_pc.
> + Therefore we are stepping away from the call line. */
> + call_line = find_pc_line (ecs->event_thread->suspend.stop_pc, 1);
> + if (call_line.line != 0)
> + {
> + stop_pc_sal.line = call_line.line;
> + stop_pc_sal.symtab = call_line.symtab;
> + }
> + }
> }
>
> /* We aren't done stepping.
I think we should use either the line number indicated by the line
table, or 0. I don't see a need to make things more complicated than that.
The preferred solution would be to use the one from the line table, but
I think that will require more changes to the stepping mechanism, so
setting the line to 0 is a nice, localized solution.
I've added a debug print to note the case:
...
+ infrun_debug_printf ("stepped to a different frame, but "
+ "it's not the start of a statement");
+
...
and I'll commit shortly.
Thanks,
- Tom
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-01-29 10:23 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-14 13:26 [PATCH][gdb/breakpoint] Fix stepping past non-stmt line-table entries Tom de Vries
2021-01-23 8:07 ` Bernd Edlinger
2021-01-29 10:23 ` Tom de Vries
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox