From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24769 invoked by alias); 31 Mar 2006 06:55:21 -0000 Received: (qmail 24758 invoked by uid 22791); 31 Mar 2006 06:55:21 -0000 X-Spam-Check-By: sourceware.org Received: from uproxy.gmail.com (HELO uproxy.gmail.com) (66.249.92.192) by sourceware.org (qpsmtpd/0.31) with ESMTP; Fri, 31 Mar 2006 06:55:18 +0000 Received: by uproxy.gmail.com with SMTP id m2so334226ugc for ; Thu, 30 Mar 2006 22:55:16 -0800 (PST) Received: by 10.66.242.15 with SMTP id p15mr47282ugh; Thu, 30 Mar 2006 22:55:16 -0800 (PST) Received: from ?192.168.1.151? ( [82.24.24.234]) by mx.gmail.com with ESMTP id j3sm5934ugd.2006.03.30.22.55.15; Thu, 30 Mar 2006 22:55:15 -0800 (PST) Message-ID: <442CC4BB.5070709@gmail.com> Date: Fri, 31 Mar 2006 07:36:00 -0000 From: Bill Pursell User-Agent: Mozilla Thunderbird 1.0.7-1.1.fc3 (X11/20050929) MIME-Version: 1.0 To: gdb@sourceware.org Subject: scope in nested function Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org X-SW-Source: 2006-03/txt/msg00228.txt.bz2 I'm not sure how to reference a variable in a nested function from gdb. In the gdb session below, there are 2 things I don't understand how to do: 1) how do I set a breakpoint in foo? (other than by referencing a line number) 2) when I'm in foo, how do I reference i? #include int main() { auto void foo(void); int i = 0; foo(); return 0; void foo(void) { i += 1; } } (gdb) b main Breakpoint 1 at 0x8048361: file d.c, line 7. (gdb) run Starting program: /home/bill/tmp/a.out Breakpoint 1, main () at d.c:7 7 int i = 0; (gdb) b foo Function "foo" not defined. Make breakpoint pending on future shared library load? (y or [n]) n (gdb) n 8 foo(); (gdb) s foo.0 () at d.c:11 11 void foo(void) { (gdb) p i No symbol "i" in current context. (gdb) n 12 i += 1; (gdb) cont Continuing. Program exited normally.