public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug gdb/31436] New: <error reading variable: value has been optimized out> with .cfi_undefined
@ 2024-02-29 17:55 lukas.graetz@tu-darmstadt.de
  2024-02-29 18:07 ` [Bug gdb/31436] " lukas.graetz@tu-darmstadt.de
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: lukas.graetz@tu-darmstadt.de @ 2024-02-29 17:55 UTC (permalink / raw)
  To: gdb-prs

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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-03-01  7:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-29 17:55 [Bug gdb/31436] New: <error reading variable: value has been optimized out> with .cfi_undefined lukas.graetz@tu-darmstadt.de
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

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).