From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 5EBE7384B0C1 for ; Mon, 22 Jun 2020 18:14:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 5EBE7384B0C1 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark@simark.ca Received: from [10.0.0.11] (173-246-6-90.qc.cable.ebox.net [173.246.6.90]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id D7F981E792; Mon, 22 Jun 2020 14:14:10 -0400 (EDT) Subject: Re: Wrong debug info for argc at -O2 To: =?UTF-8?B?5p2o5bey5b2q?= , gdb@sourceware.org References: <545669ad.7ac1.172612844b0.Coremail.yangyibiao@hust.edu.cn> From: Simon Marchi Message-ID: Date: Mon, 22 Jun 2020 14:14:10 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 MIME-Version: 1.0 In-Reply-To: <545669ad.7ac1.172612844b0.Coremail.yangyibiao@hust.edu.cn> Content-Type: text/plain; charset=utf-8 Content-Language: fr Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, BODY_8BITS, KAM_DMARC_STATUS, KAM_NUMSUBJECT, KAM_SHORT, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=no 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@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 22 Jun 2020 18:14:14 -0000 On 2020-05-29 11:58 a.m., 杨已彪 wrote: > > > Consider test-case: > ... > $ cat small.c > #include > > int main(int argc, char **argv) { > char buf[6]; > char c[] = "abc"; > sprintf(buf, (char *)c, 1); > > return 0; > } > ... > > > Stepping with step and print the values of arguments: > ... > $ gcc -O2 -g small.c; gdb -q a.out > Reading symbols from a.out... > (gdb) b main > Breakpoint 1 at 0x401040: file small.c, line 5. > (gdb) r > Starting program: /home/yibiao/Debugger/a.out > > Breakpoint 1, main (argc=1, argv=0x7fffffffdff8) at small.c:5 > 5 char c[] = "abc"; > (gdb) info args argc > argc = 1 > (gdb) step > 6 sprintf(buf, (char *)c, 1); > (gdb) info args argc > argc = -8454 > (gdb) > ... > > /************************************** > We can find that at line 5, the value of argc is 1. > When stepping to line 6 with step, the value of argc is changed to -8454. > However, When stepping with stepi, the value of argc is still 1 at line 6. > > I am posting it here as I am not sure whether this is a gcc bug or a gdb bug. > By the way, I found it very difficult to determine whether a problem is caused by gdb or gcc? > Is there any suggestions? > ***************************************/ > > $ gcc --version > gcc (GCC) 10.0.1 20200419 (experimental) > Copyright (C) 2020 Free Software Foundation, Inc. > This is free software; see the source for copying conditions. There is NO > warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. > > $ gdb --version > GNU gdb (GDB) 10.0.50.20200517-git > Copyright (C) 2020 Free Software Foundation, Inc. > License GPLv3+: GNU GPL version 3 or later > This is free software: you are free to change and redistribute it. > There is NO WARRANTY, to the extent permitted by law. Hi, The only way to know is to inspect the DWARF information manually and see if it accurately describe the program. If not, it's a gcc bug. It if does, it's a gdb bug. To inspect the DWARF information, you can use `readelf --debug-dump` or `llvm-dwarfdump` (although I am a big fan of GNU tools, I find the output of llvm-dwarfdump a bit more readable). In this particular case, you'd find the DIE (Debug Info Entry) for `argc` and see how the location of that variable is described. See the DWARF spec to understand how to interpret the value. Simon