From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qk1-x741.google.com (mail-qk1-x741.google.com [IPv6:2607:f8b0:4864:20::741]) by sourceware.org (Postfix) with ESMTPS id D4D55385DC00 for ; Sat, 4 Apr 2020 16:23:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D4D55385DC00 Received: by mail-qk1-x741.google.com with SMTP id i186so2602117qke.1 for ; Sat, 04 Apr 2020 09:23:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=Dar3pW46n2aKi1EHMowb6ssB0sXkYqyEyK2rwvgx+FI=; b=GTGPaFO0GdPa0NxcRtgnYN9VgK4cF5hIlG1PjXXT66q62bQk/4wHOjc4A22wX4oB93 Tp+WWBDhsASYt42oFAfa0kbOw5nOlc1uZ9sIxDtKji4XIaOm6kJ0aIGaq+C9l4+1YXrQ nVtI35RylN1dbYHIJs6E1pLKuotmehZ1Wlh0l29Mn3kOKRgus+zQs53e2z8cvba/jlrx MmXc34sI29uJegNa0D2Q0P/zfRj//lgeJEdpzx7n/6Dkvk2yZCL05G/5+R3TrqXFjbsn Zg11mCWxxBEDYTBoZZBui/7ILCB/8LGiZ3FJ1B8rArKA5Ck4LG97mhtlwDJFvB/wEwIz 32Vw== X-Gm-Message-State: AGi0PuYd1KttQSvxKH/TSF5D4jbjHshlAehBW/bmqdGmU79K8EesO6P3 /OuhYXCPyy32fif2+Kcl6OgMWdLYlLw= X-Google-Smtp-Source: APiQypJTC3YzIuE+e8dStUB2XoXOWa+6Yv8yDW7BE7mmAEr4ffIGusAikr778AXacvExwT5hTp12cg== X-Received: by 2002:ae9:ed56:: with SMTP id c83mr13332273qkg.200.1586017380253; Sat, 04 Apr 2020 09:23:00 -0700 (PDT) Received: from [192.168.0.181] ([179.185.146.158]) by smtp.gmail.com with ESMTPSA id y9sm1799992qtc.12.2020.04.04.09.22.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 04 Apr 2020 09:22:59 -0700 (PDT) Subject: Re: [PATCH v3 2/2] Fix an undefined behavior in record_line To: Bernd Edlinger , "gdb-patches@sourceware.org" , Andrew Burgess References: <3a407c0c-e63b-4c3f-dec2-57ff7470164b@linaro.org> From: Luis Machado Message-ID: <37b43cd4-de96-7e5c-7c17-09e5887af5d0@linaro.org> Date: Sat, 4 Apr 2020 13:22:56 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/mixed; boundary="------------40EC6D957FE2D1886A7ADCCE" Content-Language: en-US X-Spam-Status: No, score=-25.2 required=5.0 tests=BAYES_00, BODY_8BITS, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Sat, 04 Apr 2020 16:23:03 -0000 This is a multi-part message in MIME format. --------------40EC6D957FE2D1886A7ADCCE Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit Hi Bernd, I messed it up, sorry. Here's the line table information again. Regards, Luis On 4/4/20 1:06 PM, Bernd Edlinger wrote: > Hi Luis, > > the attachments seem to be twice the lo-cold.c linetables, > I wonder if the hi-cold.c linetable are missing, to somehow > make the picture complete? > > Thanks > Bernd. > > On 4/4/20 3:56 PM, Luis Machado wrote: >> Hi Bernd, >> >> On 4/4/20 4:06 AM, Bernd Edlinger wrote: >>> On 4/4/20 6:21 AM, Bernd Edlinger wrote: >>>> >>>> >>>> On 4/4/20 12:53 AM, Luis Machado wrote: >>>>> Hi, >>>>> >>>>> This seems to have caused a few regressions for aarch64-linux. I'm seeing the following: >>>>> >>>>> FAIL: gdb.dwarf2/dw2-ranges-func.exp: lo-cold: step-test-3: step into foo from main >>>>> FAIL: gdb.dwarf2/dw2-ranges-func.exp: lo-cold: step-test-3: step into bar from foo >>>>> FAIL: gdb.dwarf2/dw2-ranges-func.exp: lo-cold: step-test-3: step out of bar to foo >>>>> FAIL: gdb.dwarf2/dw2-ranges-func.exp: lo-cold: step-test-3: step into foo_cold from foo >>>>> FAIL: gdb.dwarf2/dw2-ranges-func.exp: lo-cold: step-test-3: step into baz from foo_cold >>>>> FAIL: gdb.dwarf2/dw2-ranges-func.exp: lo-cold: step-test-3: step out of baz to foo_cold >>>>> FAIL: gdb.dwarf2/dw2-ranges-func.exp: lo-cold: step-test-3: step out of foo_cold to foo >>>>> FAIL: gdb.dwarf2/dw2-ranges-func.exp: lo-cold: step-test-3: step out of foo to main >>>>> FAIL: gdb.dwarf2/dw2-ranges-func.exp: hi-cold: step-test-3: step into foo from main >>>>> FAIL: gdb.dwarf2/dw2-ranges-func.exp: hi-cold: step-test-3: step into bar from foo >>>>> FAIL: gdb.dwarf2/dw2-ranges-func.exp: hi-cold: step-test-3: step out of bar to foo >>>>> FAIL: gdb.dwarf2/dw2-ranges-func.exp: hi-cold: step-test-3: step into foo_cold from foo >>>>> FAIL: gdb.dwarf2/dw2-ranges-func.exp: hi-cold: step-test-3: step into baz from foo_cold >>>>> FAIL: gdb.dwarf2/dw2-ranges-func.exp: hi-cold: step-test-3: step out of baz to foo_cold >>>>> FAIL: gdb.dwarf2/dw2-ranges-func.exp: hi-cold: step-test-3: step out of foo_cold to foo >>>>> FAIL: gdb.dwarf2/dw2-ranges-func.exp: hi-cold: step-test-3: step out of foo to main >>>>> >>>>> git bisect pointed at this commit: >>>>> >>> >>> Louis, >>> >>> So, I cannot do much, to debug aarch64 here. >>> I would however like to know what the output of the test result is, >>> when it fails, that is where the step does stop when it is not where it should. >> >> On a quick look, we're stopping at the wrong location during an attempt to break at "main". I think things just derail from there. >> >> For now, please find attached a couple logs, one without regressions and one with the failing tests. >> >> Also, I've attached the decoded/raw line information for both binaries from this testcase. I can play with it further to get more information if you need. Hopefully this data is useful for now. >> >> Let me know otherwise. >> >>> >>> And how the line table looks in the test case when it is compiled on aarch64, >>> btw. which gcc version do you use? >> >> The compiler version is gcc version 7.4.0 (Ubuntu/Linaro 7.4.0-1ubuntu1~18.04.1). >> >>> >>> Thanks >>> Bernd. >>> >>>> >>>> Oh, dear. >>>> >>>> Andrew, please watch out, >>>> >>>> your other patch is also about to >>>> change something in this area. >>>> >>>> I tested on x86_64 where everything looked good, >>>> (at least for me, but sime test cases are always faling >>>> or are unstable ...) >>>> >>>> It could be that your patch >>>> >>>> PATCH 2/2] gdb: Preserve is-stmt lines when switch between files >>>> >>>> I just saw in my inbox is also trying to address the same issue. >>>> >>>> I was not aware that you were working on the same issue. >>>> >>>> >>>> Thanks >>>> Bernd. >>>> >>>>> --- >>>>> >>>>> commit 64dc2d4bd24ff7119c913fff91184414f09b8042 >>>>> Author: Bernd Edlinger >>>>> Date:   Thu Mar 12 11:52:34 2020 +0100 >>>>> >>>>>      Fix an undefined behavior in record_line >>>>> >>>>>      Additionally do not completely remove symbols >>>>>      at the same PC than the end marker, instead >>>>>      make them non-is-stmt breakpoints. >>>>> >>>>>      2020-04-01  Bernd Edlinger  >>>>> >>>>>              * buildsym.c (record_line): Fix undefined behavior and preserve lines at eof. >>>>> >>>>> --- >>>>> >>>>> What i see in the log is stepping through lines not working as expected. >>>>> >>>>> >>>>> On 3/27/20 12:50 AM, Bernd Edlinger wrote: >>>>>> Additionally do not completely remove symbols >>>>>> at the same PC than the end marker, instead >>>>>> make them non-is-stmt breakpoints. >>>>>> >>>>>> 2020-03-27  Bernd Edlinger  >>>>>>      * buildsym.c (record_line): Fix undefined behavior and preserve >>>>>>      lines at eof. >>>>>> --- >>>>>>    gdb/buildsym.c | 34 ++++++++++++++++++---------------- >>>>>>    1 file changed, 18 insertions(+), 16 deletions(-) >>>>>> >>>>>> diff --git a/gdb/buildsym.c b/gdb/buildsym.c >>>>>> index 2d1e441..46c5bb1 100644 >>>>>> --- a/gdb/buildsym.c >>>>>> +++ b/gdb/buildsym.c >>>>>> @@ -705,27 +705,29 @@ struct blockvector * >>>>>>                  * sizeof (struct linetable_entry)))); >>>>>>        } >>>>>>    -  /* Normally, we treat lines as unsorted.  But the end of sequence >>>>>> -     marker is special.  We sort line markers at the same PC by line >>>>>> -     number, so end of sequence markers (which have line == 0) appear >>>>>> -     first.  This is right if the marker ends the previous function, >>>>>> -     and there is no padding before the next function.  But it is >>>>>> -     wrong if the previous line was empty and we are now marking a >>>>>> -     switch to a different subfile.  We must leave the end of sequence >>>>>> -     marker at the end of this group of lines, not sort the empty line >>>>>> -     to after the marker.  The easiest way to accomplish this is to >>>>>> -     delete any empty lines from our table, if they are followed by >>>>>> -     end of sequence markers.  All we lose is the ability to set >>>>>> -     breakpoints at some lines which contain no instructions >>>>>> -     anyway.  */ >>>>>> +  /* The end of sequence marker is special.  We need to reset the >>>>>> +     is_stmt flag on previous lines at the same PC, otherwise these >>>>>> +     lines may cause problems since they might be at the same address >>>>>> +     as the following function.  For instance suppose a function calls >>>>>> +     abort there is no reason to emit a ret after that point (no joke). >>>>>> +     So the label may be at the same address where the following >>>>>> +     function begins.  A similar problem appears if a label is at the >>>>>> +     same address where an inline function ends we cannot reliably tell >>>>>> +     if this is considered part of the inline function or the calling >>>>>> +     program or even the next inline function, so stack traces may >>>>>> +     give surprising results.  Expect gdb.cp/step-and-next-inline.exp >>>>>> +     to fail if these lines are not modified here.  */ >>>>>>      if (line == 0 && subfile->line_vector->nitems > 0) >>>>>>        { >>>>>> -      e = subfile->line_vector->item + subfile->line_vector->nitems - 1; >>>>>> -      while (subfile->line_vector->nitems > 0 && e->pc == pc) >>>>>> +      e = subfile->line_vector->item + subfile->line_vector->nitems; >>>>>> +      do >>>>>>        { >>>>>>          e--; >>>>>> -      subfile->line_vector->nitems--; >>>>>> +      if (e->pc != pc || e->line == 0) >>>>>> +        break; >>>>>> +      e->is_stmt = 0; >>>>>>        } >>>>>> +      while (e > subfile->line_vector->item); >>>>>>        } >>>>>>        e = subfile->line_vector->item + subfile->line_vector->nitems++; >>>>>> --------------40EC6D957FE2D1886A7ADCCE Content-Type: text/plain; charset=UTF-8; name="dw2-ranges-func-hi-cold.l" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="dw2-ranges-func-hi-cold.l" Raw dump of debug contents of section .debug_line: Offset: 0x0 Length: 413 DWARF Version: 2 Prologue Length: 170 Minimum Instruction Length: 1 Initial value of 'is_stmt': 1 Line Base: 1 Line Range: 1 Opcode Base: 10 Opcodes: Opcode 1 has 0 args Opcode 2 has 1 arg Opcode 3 has 1 arg Opcode 4 has 1 arg Opcode 5 has 1 arg Opcode 6 has 0 args Opcode 7 has 0 args Opcode 8 has 0 args Opcode 9 has 1 arg The Directory Table (offset 0x18): 1 /home/user/build/binutils-gdb-master/gdb/testsuite/../../../../repos/binutils-gdb/gdb/testsuite/gdb.dwarf2 The File Name Table (offset 0x96): Entry Dir Time Size Name 1 1 0 0 dw2-ranges-func-hi-cold.c Line Number Statements: [0x000000b4] Extended opcode 2: set Address to 0x73c [0x000000bf] Advance Line by 75 to 76 [0x000000c2] Copy [0x000000c3] Extended opcode 2: set Address to 0x744 [0x000000ce] Advance Line by 2 to 78 [0x000000d0] Copy [0x000000d1] Extended opcode 2: set Address to 0x748 [0x000000dc] Advance Line by 2 to 80 [0x000000de] Copy [0x000000df] Extended opcode 2: set Address to 0x754 [0x000000ea] Advance Line by 2 to 82 [0x000000ec] Copy [0x000000ed] Extended opcode 1: End of Sequence [0x000000f0] Extended opcode 2: set Address to 0x6e4 [0x000000fb] Advance Line by 45 to 46 [0x000000fd] Copy [0x000000fe] Extended opcode 2: set Address to 0x6ec [0x00000109] Advance Line by 2 to 48 [0x0000010b] Copy [0x0000010c] Extended opcode 2: set Address to 0x6f0 [0x00000117] Advance Line by 2 to 50 [0x00000119] Copy [0x0000011a] Extended opcode 2: set Address to 0x708 [0x00000125] Advance Line by 2 to 52 [0x00000127] Copy [0x00000128] Extended opcode 2: set Address to 0x714 [0x00000133] Advance Line by 1 to 53 [0x00000135] Copy [0x00000136] Extended opcode 1: End of Sequence [0x00000139] Extended opcode 2: set Address to 0x714 [0x00000144] Advance Line by 57 to 58 [0x00000146] Copy [0x00000147] Advance PC by 8 to 0x71c [0x00000149] Advance Line by 1 to 59 [0x0000014b] Copy [0x0000014c] Extended opcode 1: End of Sequence [0x0000014f] Extended opcode 2: set Address to 0x734 [0x0000015a] Advance Line by 71 to 72 [0x0000015d] Copy [0x0000015e] Advance PC by 8 to 0x73c [0x00000160] Advance Line by 1 to 73 [0x00000162] Copy [0x00000163] Extended opcode 1: End of Sequence [0x00000166] Extended opcode 2: set Address to 0x71c [0x00000171] Advance Line by 61 to 62 [0x00000173] Copy [0x00000174] Extended opcode 2: set Address to 0x724 [0x0000017f] Advance Line by 2 to 64 [0x00000181] Copy [0x00000182] Extended opcode 2: set Address to 0x728 [0x0000018d] Advance Line by 2 to 66 [0x0000018f] Copy [0x00000190] Extended opcode 2: set Address to 0x734 [0x0000019b] Advance Line by 1 to 67 [0x0000019d] Copy [0x0000019e] Extended opcode 1: End of Sequence --------------40EC6D957FE2D1886A7ADCCE Content-Type: text/plain; charset=UTF-8; name="dw2-ranges-func-hi-cold.L" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="dw2-ranges-func-hi-cold.L" Contents of the .debug_line section: dw2-ranges-func-hi-cold.c: File name Line number Starting address View dw2-ranges-func-hi-cold.c 76 0x73c dw2-ranges-func-hi-cold.c 78 0x744 dw2-ranges-func-hi-cold.c 80 0x748 dw2-ranges-func-hi-cold.c 82 0x754 dw2-ranges-func-hi-cold.c 82 0x754 1 dw2-ranges-func-hi-cold.c 46 0x6e4 dw2-ranges-func-hi-cold.c 48 0x6ec dw2-ranges-func-hi-cold.c 50 0x6f0 dw2-ranges-func-hi-cold.c 52 0x708 dw2-ranges-func-hi-cold.c 53 0x714 dw2-ranges-func-hi-cold.c 53 0x714 1 dw2-ranges-func-hi-cold.c 58 0x714 dw2-ranges-func-hi-cold.c 59 0x71c dw2-ranges-func-hi-cold.c 59 0x71c 1 dw2-ranges-func-hi-cold.c 72 0x734 dw2-ranges-func-hi-cold.c 73 0x73c dw2-ranges-func-hi-cold.c 73 0x73c 1 dw2-ranges-func-hi-cold.c 62 0x71c dw2-ranges-func-hi-cold.c 64 0x724 dw2-ranges-func-hi-cold.c 66 0x728 dw2-ranges-func-hi-cold.c 67 0x734 dw2-ranges-func-hi-cold.c 67 0x734 1 --------------40EC6D957FE2D1886A7ADCCE Content-Type: text/plain; charset=UTF-8; name="dw2-ranges-func-lo-cold.l" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="dw2-ranges-func-lo-cold.l" Raw dump of debug contents of section .debug_line: Offset: 0x0 Length: 413 DWARF Version: 2 Prologue Length: 170 Minimum Instruction Length: 1 Initial value of 'is_stmt': 1 Line Base: 1 Line Range: 1 Opcode Base: 10 Opcodes: Opcode 1 has 0 args Opcode 2 has 1 arg Opcode 3 has 1 arg Opcode 4 has 1 arg Opcode 5 has 1 arg Opcode 6 has 0 args Opcode 7 has 0 args Opcode 8 has 0 args Opcode 9 has 1 arg The Directory Table (offset 0x18): 1 /home/user/build/binutils-gdb-master/gdb/testsuite/../../../../repos/binutils-gdb/gdb/testsuite/gdb.dwarf2 The File Name Table (offset 0x96): Entry Dir Time Size Name 1 1 0 0 dw2-ranges-func-lo-cold.c Line Number Statements: [0x000000b4] Extended opcode 2: set Address to 0x73c [0x000000bf] Advance Line by 75 to 76 [0x000000c2] Copy [0x000000c3] Extended opcode 2: set Address to 0x744 [0x000000ce] Advance Line by 2 to 78 [0x000000d0] Copy [0x000000d1] Extended opcode 2: set Address to 0x748 [0x000000dc] Advance Line by 2 to 80 [0x000000de] Copy [0x000000df] Extended opcode 2: set Address to 0x754 [0x000000ea] Advance Line by 2 to 82 [0x000000ec] Copy [0x000000ed] Extended opcode 1: End of Sequence [0x000000f0] Extended opcode 2: set Address to 0x70c [0x000000fb] Advance Line by 65 to 66 [0x000000fe] Copy [0x000000ff] Extended opcode 2: set Address to 0x714 [0x0000010a] Advance Line by 2 to 68 [0x0000010c] Copy [0x0000010d] Extended opcode 2: set Address to 0x718 [0x00000118] Advance Line by 2 to 70 [0x0000011a] Copy [0x0000011b] Extended opcode 2: set Address to 0x730 [0x00000126] Advance Line by 2 to 72 [0x00000128] Copy [0x00000129] Extended opcode 2: set Address to 0x73c [0x00000134] Advance Line by 1 to 73 [0x00000136] Copy [0x00000137] Extended opcode 1: End of Sequence [0x0000013a] Extended opcode 2: set Address to 0x704 [0x00000145] Advance Line by 61 to 62 [0x00000147] Copy [0x00000148] Advance PC by 8 to 0x70c [0x0000014a] Advance Line by 1 to 63 [0x0000014c] Copy [0x0000014d] Extended opcode 1: End of Sequence [0x00000150] Extended opcode 2: set Address to 0x6e4 [0x0000015b] Advance Line by 47 to 48 [0x0000015d] Copy [0x0000015e] Advance PC by 8 to 0x6ec [0x00000160] Advance Line by 1 to 49 [0x00000162] Copy [0x00000163] Extended opcode 1: End of Sequence [0x00000166] Extended opcode 2: set Address to 0x6ec [0x00000171] Advance Line by 51 to 52 [0x00000173] Copy [0x00000174] Extended opcode 2: set Address to 0x6f4 [0x0000017f] Advance Line by 2 to 54 [0x00000181] Copy [0x00000182] Extended opcode 2: set Address to 0x6f8 [0x0000018d] Advance Line by 2 to 56 [0x0000018f] Copy [0x00000190] Extended opcode 2: set Address to 0x704 [0x0000019b] Advance Line by 1 to 57 [0x0000019d] Copy [0x0000019e] Extended opcode 1: End of Sequence --------------40EC6D957FE2D1886A7ADCCE Content-Type: text/plain; charset=UTF-8; name="dw2-ranges-func-lo-cold.L" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="dw2-ranges-func-lo-cold.L" Contents of the .debug_line section: dw2-ranges-func-lo-cold.c: File name Line number Starting address View dw2-ranges-func-lo-cold.c 76 0x73c dw2-ranges-func-lo-cold.c 78 0x744 dw2-ranges-func-lo-cold.c 80 0x748 dw2-ranges-func-lo-cold.c 82 0x754 dw2-ranges-func-lo-cold.c 82 0x754 1 dw2-ranges-func-lo-cold.c 66 0x70c dw2-ranges-func-lo-cold.c 68 0x714 dw2-ranges-func-lo-cold.c 70 0x718 dw2-ranges-func-lo-cold.c 72 0x730 dw2-ranges-func-lo-cold.c 73 0x73c dw2-ranges-func-lo-cold.c 73 0x73c 1 dw2-ranges-func-lo-cold.c 62 0x704 dw2-ranges-func-lo-cold.c 63 0x70c dw2-ranges-func-lo-cold.c 63 0x70c 1 dw2-ranges-func-lo-cold.c 48 0x6e4 dw2-ranges-func-lo-cold.c 49 0x6ec dw2-ranges-func-lo-cold.c 49 0x6ec 1 dw2-ranges-func-lo-cold.c 52 0x6ec dw2-ranges-func-lo-cold.c 54 0x6f4 dw2-ranges-func-lo-cold.c 56 0x6f8 dw2-ranges-func-lo-cold.c 57 0x704 dw2-ranges-func-lo-cold.c 57 0x704 1 --------------40EC6D957FE2D1886A7ADCCE--