From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qk1-x733.google.com (mail-qk1-x733.google.com [IPv6:2607:f8b0:4864:20::733]) by sourceware.org (Postfix) with ESMTPS id 383A03851C07 for ; Mon, 22 Jun 2020 18:53:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 383A03851C07 Received: by mail-qk1-x733.google.com with SMTP id w1so16525244qkw.5 for ; Mon, 22 Jun 2020 11:53:20 -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 :content-transfer-encoding; bh=gRp/FeIxAgKGJk+XtXwVguVpF9Vfff/RY6gn7HvV/cg=; b=dA91fMc+jHM2FX8cNgnVeKt5qahzjJAk5tVz/6D627f8OoOd8MUVQg7CnEL7UgwEAh 1tv6hEWu4g6LsColnwv1kZ1Go6weiQV1qawpuPKBbkyW3UY6QtbN/UyheGNjqMc83BVk F/bJxTls/GTOlYJ2kmNl04K23+0iocaMMmn63t3rJWCoqeWtfwbQkNC2WXH7jN1cZy6j 99nxX5YSKYcHSkjktAFb15+lATYNBt30xMNryTOcHpGgl2B9IbMKOXOJCHeAtV+PQJ2n xbsKF4fsOxkqOl+hIBR10eo32NNjFRxUMKDqJvvPs7FomFKlwizxQpros65e63y9s5PA rHlg== X-Gm-Message-State: AOAM532b9oX6mBR1QJn/dDUnn0SkJfh4MWQIxJZKq4cGldbGZB3FEjT0 PtMW8deOYmuCatpwCKmCTIBrIDHxsjc= X-Google-Smtp-Source: ABdhPJy97hImNB5oFfYmVvXI+Tp2fc6q2TUVKUAbtvKAXMQy90XoRWOXXK8gePapfH749srFb/euDg== X-Received: by 2002:a37:f71e:: with SMTP id q30mr5375006qkj.68.1592851999431; Mon, 22 Jun 2020 11:53:19 -0700 (PDT) Received: from [192.168.0.185] ([179.177.236.228]) by smtp.gmail.com with ESMTPSA id n1sm14693747qkf.54.2020.06.22.11.53.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 22 Jun 2020 11:53:18 -0700 (PDT) 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: Luis Machado Message-ID: Date: Mon, 22 Jun 2020 15:53:15 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 In-Reply-To: <545669ad.7ac1.172612844b0.Coremail.yangyibiao@hust.edu.cn> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00, BODY_8BITS, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, 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:53:22 -0000 On 5/29/20 12:58 PM, 杨已彪 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) What architecture is this? If you want precise debug information, you should use -O0 instead. With O2 you are likely to run into situations where the debug info has been lost or is just incorrect. With that said, GCC has improved over the past few years in terms of debug info generation for O2+.