* gdb and variadic functions
@ 2013-10-29 15:01 Krister Olofsson
2013-10-29 15:09 ` Tom Tromey
0 siblings, 1 reply; 4+ messages in thread
From: Krister Olofsson @ 2013-10-29 15:01 UTC (permalink / raw)
To: gdb
Hi,
I'm using gdb (FreeBSD 8.2/ARM) in a variadic function but the arguments
is shown wrong in gdb.
Building with -gstabs results in wrong value of argc and building with
-fvar-tracking gives wrong values of arguments in variadic functions.
I need both correct value of argc and arguments in variadic functions.
Any ideas of what causes this?
Krister
//simple.c
#include <stdio.h>
#include <stdarg.h>
void f1(int a, char* b, int count, ...)
{
va_list ap;
va_start (ap, count);
printf("a=%d\n", a);
printf("b=%s\n", b);
printf("count=%d\n", count);
va_end(ap);
}
int main(int argc, char* argv[])
{
f1(argc, argv[1], 1, 13);
return 0;
}
//////////////
# gcc --v
Using built-in specs.
Target: arm-undermydesk-freebsd
Configured with: FreeBSD/arm system compiler
Thread model: posix
gcc version 4.2.1 20070719 [FreeBSD]
# gcc simple.c -gstabs -O0 -o simple
# gdb simple
GNU gdb 6.1.1 [FreeBSD]
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain
conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "arm-marcel-freebsd"...
(gdb) break main
Breakpoint 1 at 0x852c: file simple.c, line 19.
(gdb) run "Hello"
Starting program: /usr/home/dev/simple "Hello"
Breakpoint 1, main (argc=0, argv=0xbfffed88) at simple.c:19 // argc
should be 2
19 f1(argc, argv[1], 1, 13);
(gdb) frame
#0 main (argc=2, argv=0xbfffed88) at simple.c:19
19 f1(argc, argv[1], 1, 13);
(gdb) s
f1 (a=-1073746552, b=0xbfffeeb9 "Hello", count=1) at simple.c:8 // a
should be 2
8 va_start (ap, count);
(gdb) frame
#0 f1 (a=2, b=0xbfffeeb9 "Hello", count=1) at simple.c:8
8 va_start (ap, count);
(gdb) c
Continuing.
a=2
b=Hello
count=1
Program exited normally.
(gdb) q
# gcc simple.c -ggdb -fvar-tracking -O0 -o simple
# gdb simple
GNU gdb 6.1.1 [FreeBSD]
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain
conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "arm-marcel-freebsd"...
(gdb) break main
Breakpoint 1 at 0x852c: file simple.c, line 19.
(gdb) run "Hello"
Starting program: /usr/home/dev/simple "Hello"
Breakpoint 1, main (argc=2, argv=0xbfffed88) at simple.c:19
19 f1(argc, argv[1], 1, 13);
(gdb) s
f1 (a=2, b=0xbfffeeb9 "Hello", count=-1073746552) at simple.c:8 // count
is wrong
8 va_start (ap, count);
(gdb) frame
#0 f1 (a=2, b=0xbfffeeb9 "Hello", count=-1073746552) at simple.c:8
8 va_start (ap, count);
(gdb) n
9 printf("a=%d\n", a);
(gdb) p count
$1 = -1073746552
(gdb) n
a=2
10 printf("b=%s\n", b);
(gdb)
b=Hello
11 printf("count=%d\n", count);
(gdb)
count=1
13 }
(gdb)
main (argc=2, argv=0xbfffed88) at simple.c:20
20 return 0;
(gdb)
21 }
(gdb)
0x000083dc in __start ()
(gdb) c
Continuing.
Program exited normally.
(gdb) q
#
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: gdb and variadic functions
2013-10-29 15:01 gdb and variadic functions Krister Olofsson
@ 2013-10-29 15:09 ` Tom Tromey
2013-10-29 15:16 ` Krister Olofsson
0 siblings, 1 reply; 4+ messages in thread
From: Tom Tromey @ 2013-10-29 15:09 UTC (permalink / raw)
To: Krister Olofsson; +Cc: gdb
>>>>> "Krister" == Krister Olofsson <krister.olofsson@gmail.com> writes:
Krister> Building with -gstabs results in wrong value of argc and building with
Krister> -fvar-tracking gives wrong values of arguments in variadic functions.
It's better not to use stabs.
Krister> gcc version 4.2.1 20070719 [FreeBSD]
Krister> GNU gdb 6.1.1 [FreeBSD]
You're using an old version of gcc and an amazingly old version of gdb.
Using more current versions makes your test case work for me. So the
simple answer is that you are probably seeing a bug that was fixed
sometime in the last 6 years (gcc) or 9 years (gdb).
Offhand I don't know what the bug might be.
Tom
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: gdb and variadic functions
2013-10-29 15:09 ` Tom Tromey
@ 2013-10-29 15:16 ` Krister Olofsson
2013-10-29 19:07 ` Tom Tromey
0 siblings, 1 reply; 4+ messages in thread
From: Krister Olofsson @ 2013-10-29 15:16 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb
Hi,
yes I know that the versions is very old but it's the latest released
for FreeBSD/ARM that I can find. Porting a new version could take some
time...
//Krister
On 10/29/2013 04:09 PM, Tom Tromey wrote:
>>>>>> "Krister" == Krister Olofsson <krister.olofsson@gmail.com> writes:
>
> Krister> Building with -gstabs results in wrong value of argc and building with
> Krister> -fvar-tracking gives wrong values of arguments in variadic functions.
>
> It's better not to use stabs.
>
> Krister> gcc version 4.2.1 20070719 [FreeBSD]
> Krister> GNU gdb 6.1.1 [FreeBSD]
>
> You're using an old version of gcc and an amazingly old version of gdb.
>
> Using more current versions makes your test case work for me. So the
> simple answer is that you are probably seeing a bug that was fixed
> sometime in the last 6 years (gcc) or 9 years (gdb).
>
> Offhand I don't know what the bug might be.
>
> Tom
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: gdb and variadic functions
2013-10-29 15:16 ` Krister Olofsson
@ 2013-10-29 19:07 ` Tom Tromey
0 siblings, 0 replies; 4+ messages in thread
From: Tom Tromey @ 2013-10-29 19:07 UTC (permalink / raw)
To: Krister Olofsson; +Cc: gdb
>>>>> "Krister" == Krister Olofsson <krister.olofsson@gmail.com> writes:
Krister> yes I know that the versions is very old but it's the latest released
Krister> for FreeBSD/ARM that I can find. Porting a new version could take some
Krister> time...
Yeah. I can appreciate that. I don't know what else to suggest though.
You could try to find the bug fix to backport it; but since so much time
has elapsed it would probably be just as easy to debug it anew.
Tom
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2013-10-29 19:07 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-29 15:01 gdb and variadic functions Krister Olofsson
2013-10-29 15:09 ` Tom Tromey
2013-10-29 15:16 ` Krister Olofsson
2013-10-29 19:07 ` Tom Tromey
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox