gdb not working in variadic functions

Krister Olofsson krister.olofsson at gmail.com
Mon Sep 16 14:24:33 UTC 2013


I'm working with a board with FreeBSD 8.2 on Marvell MV78100 (Discovery
SOC) - an ARMv5TE and having problem with gdb in variadic functions.
gdb does not show the correct values of the variables.
The program executes correctly, it's just problems with gdb.
See example and source code below. Why isn't the
variable n=2?

Any clues?

//Krister

su# 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]

su# gcc main.c -O0 -g -o debug_test

su# gdb debug_test
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) b main
Breakpoint 1 at 0x8518: file main.c, line 8.
(gdb) run
Starting program: /usr/home/dev/debug_test

Breakpoint 1, main () at main.c:8
8          printf("Sum of 15 and 56 = %d\n",  sum(2, 15, 56) );
(gdb) s
sum (n=-1073746756) at main.c:18
18         va_start(ap, n);
(gdb) p n
$1 = -1073746756
(gdb) frame
#0  sum (n=-1073746756) at main.c:18
18         va_start(ap, n);
(gdb) n
19         for(i = 0; i < n; i++)
(gdb) p n
$2 = -1073746756
(gdb)


//main.c
#include <stdarg.h>
#include <stdio.h>

int sum(int, ...);

int main()
{
   printf("Sum of 15 and 56 = %d\n",  sum(2, 15, 56) );
   return 0;
}

int sum(int n, ...)
{
   int val = 0;
   va_list ap;
   int i;

   va_start(ap, n);
   for(i = 0; i < n; i++)
   {
      val += va_arg(ap, int);
   }
   va_end(ap);
   return val;
}


More information about the freebsd-arm mailing list