From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27005 invoked by alias); 29 Oct 2013 15:01:56 -0000 Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org Received: (qmail 26973 invoked by uid 89); 29 Oct 2013 15:01:54 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-la0-f48.google.com Received: from mail-la0-f48.google.com (HELO mail-la0-f48.google.com) (209.85.215.48) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Tue, 29 Oct 2013 15:01:53 +0000 Received: by mail-la0-f48.google.com with SMTP id ev20so6437467lab.21 for ; Tue, 29 Oct 2013 08:01:50 -0700 (PDT) X-Received: by 10.112.198.39 with SMTP id iz7mr464214lbc.24.1383058909737; Tue, 29 Oct 2013 08:01:49 -0700 (PDT) Received: from [10.240.22.153] (static-92-33-14-100.sme.bredbandsbolaget.se. [92.33.14.100]) by mx.google.com with ESMTPSA id a9sm1034067lae.9.2013.10.29.08.01.48 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 29 Oct 2013 08:01:48 -0700 (PDT) Message-ID: <526FCDDB.9090707@gmail.com> Date: Tue, 29 Oct 2013 15:01:00 -0000 From: Krister Olofsson User-Agent: Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Thunderbird/24.0 MIME-Version: 1.0 To: gdb@sourceware.org Subject: gdb and variadic functions Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2013-10/txt/msg00178.txt.bz2 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 #include 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 #