From owner-freebsd-arm@FreeBSD.ORG Mon Sep 16 14:24:33 2013 Return-Path: Delivered-To: freebsd-arm@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id D4FDCF30 for ; Mon, 16 Sep 2013 14:24:33 +0000 (UTC) (envelope-from krister.olofsson@gmail.com) Received: from mail-ie0-x229.google.com (mail-ie0-x229.google.com [IPv6:2607:f8b0:4001:c03::229]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id A8EE6212E for ; Mon, 16 Sep 2013 14:24:33 +0000 (UTC) Received: by mail-ie0-f169.google.com with SMTP id tp5so7514660ieb.14 for ; Mon, 16 Sep 2013 07:24:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=Mvc8UB+uoYRhB2fX6gPvVJbrSZBqLj9Mno10KRl77jI=; b=X8gQtsDumEBs3sa5D2KwrQVx4NSB/c+v9OLrz3Tm0Jnx0LbOZu4fYTl9TeTcZPsjBW dO/AiHrN7nHU6Xc+CUC+Gz1KEVC7jNPdR3tBQJx+mvVCzY8wrfU4a49yLw4Arc/qtlIp NDgpZXMDtJZRvfjWqe9lpfECPSo58NC4aApvFMHDav7eNHC7ZZ0ARM3chkW69xxudZBM +kTXEPlMOCMgAsTyuOYRL73HGL/ojoT0UETyH+pjNd6yZsqwtoUJ8PBNRgH2SMZl5GYa E+KZCaTEyj1TftrdSHaUaVrBby4Rfxt8jPMujtIl7DPyf3DmSuBJmmFABKu3VB78pIRb To4Q== MIME-Version: 1.0 X-Received: by 10.43.143.133 with SMTP id jm5mr828856icc.25.1379341473018; Mon, 16 Sep 2013 07:24:33 -0700 (PDT) Received: by 10.64.231.67 with HTTP; Mon, 16 Sep 2013 07:24:32 -0700 (PDT) Date: Mon, 16 Sep 2013 16:24:32 +0200 Message-ID: Subject: gdb not working in variadic functions From: Krister Olofsson To: freebsd-arm@freebsd.org Content-Type: text/plain; charset=UTF-8 X-Content-Filtered-By: Mailman/MimeDel 2.1.14 X-BeenThere: freebsd-arm@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Porting FreeBSD to the StrongARM Processor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 Sep 2013 14:24:33 -0000 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 #include 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; }