GDB: function parameters have garbage values on function entry

Bug #2009618 reported by Alex Coplan
6
This bug affects 1 person
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~20.04.1) 9.2
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
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://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

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/toolchain/a.out

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://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=ac4a4f1cd7dceeeb17d0b8c077c874f2247acbf0

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~20.04.1
ProcVersionSignature: Ubuntu 5.4.0-139.156-generic 5.4.224
Uname: Linux 5.4.0-139-generic x86_64
NonfreeKernelModules: nvidia_modeset nvidia
ApportVersion: 2.20.11-0ubuntu27.25
Architecture: amd64
CasperMD5CheckResult: skip
Date: Tue Mar 7 16:01:56 2023
SourcePackage: gdb
UpgradeStatus: Upgraded to focal on 2023-03-03 (4 days ago)

Revision history for this message
Alex Coplan (alecop) wrote :
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.