This is the mail archive of the gdb@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]

gdb and variadic functions


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
#



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