From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id 948FA3858405 for ; Wed, 23 Mar 2022 15:43:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 948FA3858405 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 22NF0dme006028; Wed, 23 Mar 2022 15:43:16 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 3f05tmh2j4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 23 Mar 2022 15:43:15 +0000 Received: from m0098420.ppops.net (m0098420.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 22NFTie5021199; Wed, 23 Mar 2022 15:43:15 GMT Received: from ppma01wdc.us.ibm.com (fd.55.37a9.ip4.static.sl-reverse.com [169.55.85.253]) by mx0b-001b2d01.pphosted.com with ESMTP id 3f05tmh2hx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 23 Mar 2022 15:43:15 +0000 Received: from pps.filterd (ppma01wdc.us.ibm.com [127.0.0.1]) by ppma01wdc.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 22NFNXbH010337; Wed, 23 Mar 2022 15:43:14 GMT Received: from b01cxnp23032.gho.pok.ibm.com (b01cxnp23032.gho.pok.ibm.com [9.57.198.27]) by ppma01wdc.us.ibm.com with ESMTP id 3ew6t93y7s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 23 Mar 2022 15:43:14 +0000 Received: from b01ledav001.gho.pok.ibm.com (b01ledav001.gho.pok.ibm.com [9.57.199.106]) by b01cxnp23032.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 22NFhDdm24314276 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 23 Mar 2022 15:43:13 GMT Received: from b01ledav001.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E6D4D28064; Wed, 23 Mar 2022 15:43:12 +0000 (GMT) Received: from b01ledav001.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 968242805A; Wed, 23 Mar 2022 15:43:11 +0000 (GMT) Received: from li-e362e14c-2378-11b2-a85c-87d605f3c641.ibm.com (unknown [9.211.82.62]) by b01ledav001.gho.pok.ibm.com (Postfix) with ESMTP; Wed, 23 Mar 2022 15:43:11 +0000 (GMT) Message-ID: <8d4cb47ccc61b0fc66e6f588e53c8186bbea1e85.camel@us.ibm.com> Subject: Re: [PATCH V3] Updated, fix reverse stepping multiple contiguous PC ranges From: Carl Love To: Bruno Larsen , gdb-patches@sourceware.org, luis.machado@arm.com, cel@us.ibm.com Cc: Rogerio Alves , Will Schmidt Date: Wed, 23 Mar 2022 08:43:10 -0700 In-Reply-To: <36e66d67-6593-b5c2-64e5-487242a40798@redhat.com> References: <442684e3f81aa1df073960bd45918106acefa2b9.camel@us.ibm.com> <7a429c919395db6ec4642803badca5dbb97bff66.camel@us.ibm.com> <90f842721dc87da4052ae860c8ee09286dae0012.camel@us.ibm.com> <36e66d67-6593-b5c2-64e5-487242a40798@redhat.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.28.5 (3.28.5-18.el8) Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 X-Proofpoint-GUID: fftb4BWFaFtFSEEhPtjp90xGTtRp9_q1 X-Proofpoint-ORIG-GUID: _NCbBsBLmwpl2TZf7fB3UfTMk3RClVzR X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.850,Hydra:6.0.425,FMLib:17.11.64.514 definitions=2022-03-23_07,2022-03-23_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 priorityscore=1501 phishscore=0 impostorscore=0 spamscore=0 mlxscore=0 lowpriorityscore=0 clxscore=1015 mlxlogscore=999 malwarescore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2203230084 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 23 Mar 2022 15:43:22 -0000 Bruno, GDB maintainers On Wed, 2022-03-23 at 09:20 -0300, Bruno Larsen wrote: > I think you forgot to add the testcase to the email. Also a gentle > reminder for you to remove the "//carl fix" comment and the commented > line of code above. Yes, sorry I attached the wrong patch. Actually, I had been leaving the carll fix intentionally for any additional reviewers. I updated this to V3 to make it clear that the following patch is different, i.e. that it does have the new test case. I also went ahead and removed the //carll fix so everything is now clean. Carl Love ---------------------------------------------------------- Fix reverse stepping multiple contiguous PC ranges The following patch fixes 5 test failures in gdb.reverse/solib-precsave.exp and 5 test failures in gdb.reverse/solib-reverse.exp. Both testst pass on Intel 64-bit. The two tests solib-precsave.exp and solib-reverse.exp both initially passed on Intel without the patch. No additional regression failures were seen with the patch. A new testcase was added using DWARF statements to reproduce the issue as described below. The new testcase has been tested on x86 and Powerpc with the patch to that the test case fails without the patch. The issue is fixed on both platforms with the patch. When running GDB's testsuite on aarch64-linux/Ubuntu 20.04, I noticed some failures in gdb.reverse/solib-precsave.exp and gdb.reverse/solib-reverse.exp. The failure happens around the following code: 38 b[1] = shr2(17); /* middle part two */ 40 b[0] = 6; b[1] = 9; /* generic statement, end part two */ 42 shr1 ("message 1\n"); /* shr1 one */ Normal execution: - step from line 1 will land on line 2. - step from line 2 will land on line 3. Reverse execution: - step from line 3 will land on line 2. - step from line 2 will land on line 2. - step from line 2 will land on line 1. The problem here is that line 40 contains two contiguous but distinct PC ranges, like so: Line 40 - [0x7ec ~ 0x7f4] Line 40 - [0x7f4 ~ 0x7fc] When stepping forward from line 2, we skip both of these ranges and land on line 42. When stepping backward from line 3, we stop at the start PC of the second (or first, going backwards) range of line 40. This happens because we have this check in infrun.c:process_event_stop_test: /* When stepping backward, stop at beginning of line range (unless it's the function entry point, in which case keep going back to the call point). */ CORE_ADDR stop_pc = ecs->event_thread->suspend.stop_pc; if (stop_pc == ecs->event_thread->control.step_range_start && stop_pc != ecs->stop_func_start && execution_direction == EXEC_REVERSE) end_stepping_range (ecs); else keep_going (ecs); Since we've reached ecs->event_thread->control.step_range_start, we stop stepping backwards. The right thing to do is to look for adjacent PC ranges for the same line, until we notice a line change. Then we take that as the start PC of the range. Another solution I thought about is to merge the contiguous ranges when we are reading the line tables. Though I'm not sure if we really want to process that data as opposed to keeping it as the compiler created, and then working around that. In any case, the following patch addresses this problem. I'm not particularly happy with how we go back in the ranges (using "pc - 1"). Feedback would be welcome. Validated on aarch64-linux/Ubuntu 20.04/18.04. Ubuntu 18.04 doesn't actually run into these failures because the compiler doesn't generate distinct PC ranges for the same line. gdb/ChangeLog: YYYY-MM-DD Luis Machado * infrun.c (process_event_stop_test): Handle backward stepping across multiple ranges for the same line. * symtab.c (find_line_range_start): New function. * symtab.h (find_line_range_start): New prototype. The patch includes a new test that creates a DWARF entry with two statements with the same line number to verify the patch fixes the issue. Co-authored-by: Carl Love --- gdb/infrun.c | 24 +++- gdb/symtab.c | 35 ++++++ gdb/symtab.h | 16 +++ gdb/testsuite/gdb.reverse/map-to-same-line.c | 30 +++++ .../gdb.reverse/map-to-same-line.exp | 114 ++++++++++++++++++ 5 files changed, 217 insertions(+), 2 deletions(-) create mode 100644 gdb/testsuite/gdb.reverse/map-to-same-line.c create mode 100644 gdb/testsuite/gdb.reverse/map-to-same-line.exp diff --git a/gdb/infrun.c b/gdb/infrun.c index b60c1fd238a..ad1a9695763 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -6778,12 +6778,32 @@ if (ecs->event_thread->control.proceed_to_finish have software watchpoints). */ ecs->event_thread->control.may_range_step = 1; + /* When we are stepping inside a particular line range, in reverse, + and we are sitting at the first address of that range, we need to + check if this address also shows up in another line range as the + end address. + + If so, we need to check what line such a step range points to. + If it points to the same line as the current step range, that + means we need to keep going in order to reach the first address + of the line range. We repeat this until we eventually get to the + first address of a particular line we're stepping through. */ + CORE_ADDR range_start = ecs->event_thread->control.step_range_start; + if (execution_direction == EXEC_REVERSE) + { + gdb::optional real_range_start + = find_line_range_start (ecs->event_thread->stop_pc()); + + + if (real_range_start.has_value ()) + range_start = *real_range_start; + } + /* When stepping backward, stop at beginning of line range (unless it's the function entry point, in which case keep going back to the call point). */ CORE_ADDR stop_pc = ecs->event_thread->stop_pc (); - if (stop_pc == ecs->event_thread->control.step_range_start - && stop_pc != ecs->stop_func_start + if (stop_pc == range_start && stop_pc != ecs->stop_func_start && execution_direction == EXEC_REVERSE) end_stepping_range (ecs); else diff --git a/gdb/symtab.c b/gdb/symtab.c index a867e1db9fd..600006c7843 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -3425,6 +3425,41 @@ find_pc_line (CORE_ADDR pc, int notcurrent) return sal; } +/* See symtah.h. */ + +gdb::optional +find_line_range_start (CORE_ADDR pc) +{ + struct symtab_and_line current_sal = find_pc_line (pc, 0); + + if (current_sal.line == 0) + return {}; + + struct symtab_and_line prev_sal = find_pc_line (current_sal.pc - 1, 0); + + /* If the previous entry is for a different line, that means we are already + at the entry with the start PC for this line. */ + if (prev_sal.line != current_sal.line) + return current_sal.pc; + + /* Otherwise, keep looking for entries for the same line but with + smaller PC's. */ + bool done = false; + CORE_ADDR prev_pc; + while (!done) + { + prev_pc = prev_sal.pc; + + prev_sal = find_pc_line (prev_pc - 1, 0); + + /* Did we notice a line change? If so, we are done with the search. */ + if (prev_sal.line != current_sal.line) + done = true; + } + + return prev_pc; +} + /* See symtab.h. */ struct symtab * diff --git a/gdb/symtab.h b/gdb/symtab.h index d12eee6e9d8..4d893a8a3b8 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -2149,6 +2149,22 @@ extern struct symtab_and_line find_pc_line (CORE_ADDR, int); extern struct symtab_and_line find_pc_sect_line (CORE_ADDR, struct obj_section *, int); +/* Given PC, and assuming it is part of a range of addresses that is part of a + line, go back through the linetable and find the starting PC of that + line. + + For example, suppose we have 3 PC ranges for line X: + + Line X - [0x0 - 0x8] + Line X - [0x8 - 0x10] + Line X - [0x10 - 0x18] + + If we call the function with PC == 0x14, we want to return 0x0, as that is + the starting PC of line X, and the ranges are contiguous. +*/ + +extern gdb::optional find_line_range_start (CORE_ADDR pc); + /* Wrapper around find_pc_line to just return the symtab. */ extern struct symtab *find_pc_line_symtab (CORE_ADDR); diff --git a/gdb/testsuite/gdb.reverse/map-to-same-line.c b/gdb/testsuite/gdb.reverse/map-to-same-line.c new file mode 100644 index 00000000000..d35838eccc9 --- /dev/null +++ b/gdb/testsuite/gdb.reverse/map-to-same-line.c @@ -0,0 +1,30 @@ + + +/* The purpose of this test is to create a DWARF line table that says there + are two assignment statements on the same line. The expect test checks to + make sure gdb reverse steps over each statements individulally. The test + makes sure a single reverse step doesn't step over both assignment + statements in the line. The expect file generates the DWARF assembly + statements will create a line table that with j = 3 and k = 4 listed as + being on the same source code line even though they actually are on + different lines in this source code below. Have to put them on separate + lines to be able to identify them and add them to the line table. */ +int +main (){ /* TAG: main prologue */ + asm ("main_label: .globl main_label"); + asm ("loop_start: .globl loop_start"); + int i, j, k, l, m; + + asm ("i_assignment: .globl i_assignment"); + i = 1; /* TAG: assignment i */ + asm ("j_assignment: .globl j_assignment"); + j = 3; /* TAG: assignment j */ + asm ("k_assignment: .globl k_assignment"); + k = 4; /* TAG: assignment k */ + asm ("l_assignment: .globl l_assignment"); + l = 10; /* TAG: assignment l */ + asm ("m_assignment: .globl m_assignment"); + m = 11; /* TAG: assignment m */ + asm ("main_return: .globl main_return"); + return 0; /* TAG: end of main */ +} diff --git a/gdb/testsuite/gdb.reverse/map-to-same-line.exp b/gdb/testsuite/gdb.reverse/map-to-same-line.exp new file mode 100644 index 00000000000..da407b50e94 --- /dev/null +++ b/gdb/testsuite/gdb.reverse/map-to-same-line.exp @@ -0,0 +1,114 @@ + +# The purpose of this test is to create a DWARF line table that says the +# two assignment statements are on the same line. The expect test checks +# to make sure gdb reverse steps over each statement individually, i.e. +# not over the line containing both assignments. */ + +load_lib dwarf.exp + +# This test can only be run on targets which support DWARF-2 and use gas. +if {![dwarf2_support]} { + unsupported "dwarf2 support required for this test" + return 0 +} + +if [get_compiler_info] { + return -1 +} + +# The DWARF assembler requires the gcc compiler. +if {!$gcc_compiled} { + unsupported "gcc is required for this test" + return 0 +} + +standard_testfile .c .S + +if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } { + return -1 +} + +set asm_file [standard_output_file $srcfile2] +Dwarf::assemble $asm_file { + global srcdir subdir srcfile + declare_labels integer_label L + + # Find start address and length of program + lassign [function_range main [list ${srcdir}/${subdir}/$srcfile]] \ + main_start main_len + set main_end "$main_start + $main_len" + + cu {} { + compile_unit { + {language @DW_LANG_C} + {name map-to-same-line.c} + {stmt_list $L DW_FORM_sec_offset} + {low_pc 0 addr} + } { + subprogram { + {external 1 flag} + {name main} + {low_pc $main_start addr} + {high_pc $main_len DW_FORM_data4} + } + } + } + + lines {version 2 default_is_stmt 1} L { + include_dir "${srcdir}/${subdir}" + file_name "$srcfile" 1 + + # Generate the line table program with the assignments to j and k + # are listed on the same source line in the table. + program { + {DW_LNE_set_address $main_start} + {line [gdb_get_line_number "TAG: main prologue"]} + {DW_LNS_copy} + + {DW_LNE_set_address i_assignment} + {line [gdb_get_line_number "TAG: assignment i"]} + {DW_LNS_copy} + + {DW_LNE_set_address j_assignment} + {line [gdb_get_line_number "TAG: assignment j"]} + {DW_LNS_copy} + + {DW_LNE_set_address k_assignment} + {line [gdb_get_line_number "TAG: assignment j"]} + {DW_LNS_copy} + + {DW_LNE_set_address l_assignment} + {line [gdb_get_line_number "TAG: assignment l"]} + {DW_LNS_copy} + + {DW_LNE_set_address m_assignment} + {line [gdb_get_line_number "TAG: assignment m"]} + {DW_LNS_copy} + + {DW_LNE_end_sequence} + } + } +} + +if { [prepare_for_testing "failed to prepare" ${testfile} \ + [list $srcfile $asm_file] {nodebug} ] } { + return -1 +} + +if ![runto_main] { + return -1 +} + +if [supports_process_record] { + # Activate process record/replay + gdb_test_no_output "record" "turn on process record" +} + +set break_at_l [gdb_get_line_number "TAG: assignment l" ] + +gdb_test "tbreak $break_at_l" "Temporary breakpoint .*" "breakpoint l = 10" + +gdb_test "continue" "Temporary breakpoint .*" "run to l = 10" +# j = 3 and k = 4 are on the same line. The reverse step stops at j = 3 +gdb_test "reverse-step" ".* j = 3;.*" "reverse-step to j = 3" +gdb_test "reverse-step" ".* i = 1;.*" "reverse-step to i = 1" -- 2.31.1