This is the mail archive of the gdb-prs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/21222] A function with a particular number of arguments corrupts a value calculated on the stack when stepping through the function


https://sourceware.org/bugzilla/show_bug.cgi?id=21222

--- Comment #3 from Adam Stylinski <kungfujesus06 at gmail dot com> ---
(In reply to Keith Seitz from comment #2)
> (In reply to Adam Stylinski from comment #0)
> > Created attachment 9872 [details]
> > Minimal test case
> > 
> > Sorry for the convoluted summary, I'm not entirely sure how or why it
> > happens.  The results are fine when not attached to the debugger (or in the
> > test case I'm providing, not stepping into the function).  
> 
> It is not clear to me what you mean here. Does the attached test case
> demonstrate the problem?
> 
> > I compiled with -O0 and -g3.  Put a break point in testFunc, step through
> > with step or next, and you'll see a corrupted value.
> 
> I cannot reproduce this with HEAD or 7.12.1.20170306-git.
> 
> Is it possible that the compiler is re-using unused registers? "info frame",
> "info addr", and "disass" should be helpful here to determine if this is the
> happening.
> 
> Out of curiosity, what compiler are you using?

Yep, that test case does produce the behavior for me. I used g++, that bit
might matter.  I forgot to add one important bit: I added -march=native, which
my case is a Haswell based CPU.  But...all optimizations should be turned off,
so I'm not entirely sure what that's about.  In any case, while not attached to
the debugger, I do not get this issue.

adam@Crushinator:~$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/6.3.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc/src/gcc/configure --prefix=/usr --libdir=/usr/lib
--libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info
--with-bugurl=https://bugs.archlinux.org/
--enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared
--enable-threads=posix --enable-libmpx --with-system-zlib --with-isl
--enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu
--disable-libstdcxx-pch --disable-libssp --enable-gnu-unique-object
--enable-linker-build-id --enable-lto --enable-plugin
--enable-install-libiberty --with-linker-hash-style=gnu
--enable-gnu-indirect-function --disable-multilib --disable-werror
--enable-checking=release
Thread model: posix
gcc version 6.3.1 20170109 (GCC) 

adam@Crushinator:~$ /lib/libc.so.6 
GNU C Library (GNU libc) stable release version 2.24, by Roland McGrath et al.
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
Compiled by GNU CC version 6.1.1 20160802.
Available extensions:
        crypt add-on version 2.1 by Michael Glad and others
        GNU Libidn by Simon Josefsson
        Native POSIX Threads Library by Ulrich Drepper et al
        BIND-8.2.3-T5B
libc ABIs: UNIQUE IFUNC
For bug reporting instructions, please see:
<https://bugs.archlinux.org/>.

adam@Crushinator:~$ gdb --version
GNU gdb (GDB) 7.12.1
Copyright (C) 2017 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-pc-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".


Without debugger:
adam@Crushinator:~$ ./testfunc.out 
lambda = 0.031557

With:

adam@Crushinator:~$ g++ -O0 -g3 -march=native testfunc.cpp -o testfunc.out
adam@Crushinator:~$ gdb ./testfunc.out 
GNU gdb (GDB) 7.12.1
Copyright (C) 2017 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-pc-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 ./testfunc.out...done.
(gdb) break testFunc
Breakpoint 1 at 0x400550: file testfunc.cpp, line 12.
(gdb) r
Starting program: /home/adam/testfunc.out 

Breakpoint 1, testFunc (a=0x0, n=0, sx=0x0, sy=0x0, rc=0x0, nr=0, b=4,
f=9.50000026e+09, c=0x0, d=0x0, e=0x0, gx=0x0, gy=0x0) at testfunc.cpp:12
12          float lambda = C_LIGHT / f;
(gdb) n
13          printf("lambda = %f\n", lambda);
(gdb) p lambda
$1 = -5.38359187e+25

-- 
You are receiving this mail because:
You are on the CC list for the bug.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]