GDB: function parameters have garbage values on function entry
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
gdb (Ubuntu) |
New
|
Undecided
|
Unassigned |
Bug Description
After upgrading from Ubuntu 18.04 to Ubuntu 20.04 on my x86_64 desktop machine, I've noticed a significant regression in the debug experience with gdb. In particular, function parameters in GDB now seem to reliably have garbage values on entry to the function until I step once inside the function. Here is a reproducer:
$ cat test.c
#include <stdio.h>
int f(int x, int y) {
printf ("%d, %d\n", x, y);
}
int main(void) {
f(2,3);
}
$ gcc -g3 test.c
$ gdb a.out
GNU gdb (Ubuntu 9.2-0ubuntu1~
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://
Find the GDB manual and other documentation resources online at:
<http://
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from a.out...
(gdb) b f
Breakpoint 1 at 0x1149: file test.c, line 2.
(gdb) r
Starting program: /data_sdb/
Breakpoint 1, f (x=21845, y=1431654496) at test.c:2
2 int f(int x, int y) {
(gdb) p x
$1 = 21845
(gdb) p y
$2 = 1431654496
(gdb) n
3 printf ("%d, %d\n", x, y);
(gdb) p x
$3 = 2
(gdb) p y
$4 = 3
I tried compiling GDB from source and noticed that I could reproduce the problem with GDB 9 but not with GDB 10. A bisection showed that the following GDB commit fixed the issue: https:/
Perhaps that patch should be backported to GDB 9, but it's not entirely clear why the prologue analysis is even necessary in this case.
ProblemType: Bug
DistroRelease: Ubuntu 20.04
Package: gdb 9.2-0ubuntu1~
ProcVersionSign
Uname: Linux 5.4.0-139-generic x86_64
NonfreeKernelMo
ApportVersion: 2.20.11-
Architecture: amd64
CasperMD5CheckR
Date: Tue Mar 7 16:01:56 2023
SourcePackage: gdb
UpgradeStatus: Upgraded to focal on 2023-03-03 (4 days ago)