Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 16 Sep 2013 16:24:32 +0200
From:      Krister Olofsson <krister.olofsson@gmail.com>
To:        freebsd-arm@freebsd.org
Subject:   gdb not working in variadic functions
Message-ID:  <CAAY5Z-OZtKrN_RtjRTfC=F23iL2e3W5MxR4jbiiMVmvpPEh5TA@mail.gmail.com>

next in thread | raw e-mail | index | archive | help
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;
}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAAY5Z-OZtKrN_RtjRTfC=F23iL2e3W5MxR4jbiiMVmvpPEh5TA>