public inbox for gdb-prs@sourceware.org help / color / mirror / Atom feed
From: "lukas.graetz@tu-darmstadt.de" <sourceware-bugzilla@sourceware.org> To: gdb-prs@sourceware.org Subject: [Bug gdb/31436] New: <error reading variable: value has been optimized out> with .cfi_undefined Date: Thu, 29 Feb 2024 17:55:14 +0000 [thread overview] Message-ID: <bug-31436-4717@http.sourceware.org/bugzilla/> (raw) https://sourceware.org/bugzilla/show_bug.cgi?id=31436 Bug ID: 31436 Summary: <error reading variable: value has been optimized out> with .cfi_undefined Product: gdb Version: 15.1 Status: UNCONFIRMED Severity: normal Priority: P2 Component: gdb Assignee: unassigned at sourceware dot org Reporter: lukas.graetz@tu-darmstadt.de Target Milestone: --- Created attachment 15384 --> https://sourceware.org/bugzilla/attachment.cgi?id=15384&action=edit bar-artificial.zip Backstory: Currently, the gcc trunk (14.0.1 20240228 (experimental)) has an optimization to not save callee-saved registers for noreturn functions [1]. It was observed in [2] that gdb printed out incorrect variable values due to clobbered registers. A fix adds ".cfi_undefined" annotations [3]. --- The problem for gdb: The backtrace is still incorrect (also observed in [2]): $ gdb bar-artificial-fix-undefined GNU gdb (GDB) 15.0.50.20240229-git (gdb) run Starting program: bar-artificial-fix-undefined Program received signal SIGABRT, Aborted. 0x00007ffff7dee00b in raise () from /lib/x86_64-linux-gnu/libc.so.6 (gdb) bt #0 0x00007ffff7dee00b in raise () from /lib/x86_64-linux-gnu/libc.so.6 #1 0x00007ffff7dcd859 in abort () from /lib/x86_64-linux-gnu/libc.so.6 #2 0x00000000004011b0 in bar () at bar-artificial.c:30 #3 0x00000000004011d1 in baz ( a=<error reading variable: value has been optimised out>, b=<optimised out>, c=<optimised out>, d=<optimised out>, e=<optimised out>, f=<optimised out>, g=48, h=49) at bar-artificial.c:38 Here, the backtrace did not reach the functions qux() and main(). In this case, the stack base pointer rbp was clobbered and marked with .cfi_undefined. But it still should be possible without rbp to reconstruct the backtrace. --- There is also another patch [4] to partially revert [1] by saving rbp only. When applying this patch (and manually adding .cfi_undefined to the assembler output, because both patches [3],[4] are incompatible), we get the following result: $ gdb bar-artificial-save-rbp (gdb) run Program received signal SIGABRT, Aborted. (gdb) bt #0 0x00007ffff7dee00b in raise () from /lib/x86_64-linux-gnu/libc.so.6 #1 0x00007ffff7dcd859 in abort () from /lib/x86_64-linux-gnu/libc.so.6 #2 0x00000000004011b1 in bar () at bar-artificial.c:30 #3 0x00000000004011d2 in baz (a=a@entry=42, b=b@entry=43, c=c@entry=44, d=<error reading variable: value has been optimised out>, e=<error reading variable: value has been optimised out>, f=<error reading variable: value has been optimised out>, g=48, h=49) at bar-artificial.c:38 #4 0x00000000004012aa in qux () at bar-artificial.c:55 #5 0x00000000004012e4 in main () at bar-artificial.c:62 Were it just <optimized out> it would be as expected, but the wording "error reading" still leaves the question whether there went something wrong. --- How to reproduce: See the attached .zip archive. To run it yourself, you don't need to build the gcc trunk, you can just use the .S files on x86-64. $ gcc bar-artificial-fix-undefined.S -o bar-artificial-fix-undefined $ gcc bar-artificial-save-rbp.S -o bar-artificial-save-rbp [[ Was produced by $ cc1 -Og -g bar-artificial.c -o bar-artificial-fix-undefined.S Manually edited: bar-artificial-save-rbp.S ]] --- Credit: The observation and test file come from Jakub Jelinek, see [1]. --- Additional info: The gcc optimization is disabled for -Og and could be disabled by default, because it could add more <optimized out>, even indirectly for parts that were compiled with gcc -Og. There seems to be a discussion about it in some meailing list. Nevertheless, gdb should not "error" or give up on a .cfi_undefined. [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=38534 [2] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=38534#c28 [3] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114116#c6 and https://patchwork.sourceware.org/project/gcc/list/?series=30327 [4] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114116#c2 and https://gcc.gnu.org/bugzilla/attachment.cgi?id=57545&action=diff -- You are receiving this mail because: You are on the CC list for the bug.
next reply other threads:[~2024-02-29 17:55 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-02-29 17:55 lukas.graetz@tu-darmstadt.de [this message] 2024-02-29 18:07 ` [Bug gdb/31436] " lukas.graetz@tu-darmstadt.de 2024-02-29 19:39 ` lukas.graetz@tu-darmstadt.de 2024-03-01 7:50 ` sam at gentoo dot org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-31436-4717@http.sourceware.org/bugzilla/ \ --to=sourceware-bugzilla@sourceware.org \ --cc=gdb-prs@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).