From: Krister Olofsson <krister.olofsson@gmail.com>
To: gdb@sourceware.org
Subject: gdb and variadic functions
Date: Tue, 29 Oct 2013 15:01:00 -0000 [thread overview]
Message-ID: <526FCDDB.9090707@gmail.com> (raw)
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
#
next reply other threads:[~2013-10-29 15:01 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-29 15:01 Krister Olofsson [this message]
2013-10-29 15:09 ` Tom Tromey
2013-10-29 15:16 ` Krister Olofsson
2013-10-29 19:07 ` Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=526FCDDB.9090707@gmail.com \
--to=krister.olofsson@gmail.com \
--cc=gdb@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox