From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2225 invoked by alias); 12 Aug 2009 23:10:34 -0000 Received: (qmail 2176 invoked by uid 22791); 12 Aug 2009 23:10:33 -0000 X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=BAYES_00,J_CHICKENPOX_15 X-Spam-Check-By: sourceware.org Received: from mail35c.att-webhosting.com (HELO mail35c.att-webhosting.com) (161.58.104.132) by sourceware.org (qpsmtpd/0.43rc1) with SMTP; Wed, 12 Aug 2009 23:10:24 +0000 Received: from mx22.stngva01.us.mxservers.net (204.202.242.39) by mail35c.att-webhosting.com (RS ver 1.0.95vs) with SMTP id 0-0257858620 for ; Wed, 12 Aug 2009 19:10:21 -0400 (EDT) Received: from unknown [198.66.164.83] (EHLO mxw3501.att-webhosting.com) by va1-mx22.stngva01.us.mxservers.net (mxl_mta-3.1.0-05) with ESMTP id bbb438a4.2557795232.102838.00-007.va1-mx22.stngva01.us.mxservers.net (envelope-from ); Wed, 12 Aug 2009 19:09:47 -0400 (EDT) Received: (qmail 10659 invoked from network); 12 Aug 2009 23:10:20 -0000 Received: from unknown (HELO ?192.168.1.2?) (selcuk@85.106.170.207) by with ESMTPA; 12 Aug 2009 23:10:20 -0000 Subject: recursive user-defined commands and From: Selcuk Kopru Reply-To: selcuk.kopru@tyazilimevi.com To: gdb@sourceware.org Content-Type: text/plain Date: Wed, 12 Aug 2009 23:10:00 -0000 Message-Id: <1250118614.3975.43.camel@selcuk-laptop> Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-MAIL-FROM: X-SF-Loop: 1 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 X-SW-Source: 2009-08/txt/msg00089.txt.bz2 Hi, I'm trying to write user-defined commands to view some nested/embedded classes which form a huge data hierarchy. Problems arise if the commands are recursive because the convenience variables are not defined in the command-scope. At least, that's what I'm suspecting. For example, the structures can contain lists of lists which force me to use recursive commands. Here is a portion of the code that I'm trying to run in gdb. define show_data if $arg0->m_ClassID == 15 show_number $arg0 end if $arg0->m_ClassID == 16 show_simple $arg0 end if $arg0->m_ClassID == 17 show_string $arg0 end if $arg0->m_ClassID == 18 show_list $arg0 end if $arg0->m_ClassID == 20 show_dag $arg0 end ... end define show_number printf "%d", ((CMyNumberValue*)$arg0).m_Value end define show_simple printf "%d", ((CMySimpleValue*)$arg0).m_ID end define show_string wchar_print ((CMyString*)$arg0).m_Value end define show_list printf "# " set $llist = ((CMyList*)$arg0).m_FeatList.m_First while ($llist != 0) show_value $llist->Data set $llist = $llist->Next end printf " #" end define show_dag printf "[ " set ($dlist) = ((CMyDag*)$arg0).m_FVList.m_First while ($dlist != 0) show_value ($dlist)->Data printf "\n" set $dlist = ($dlist)->Next end printf " ]" end If the "show_dag" command is being hit for the second time in the same call sequence then the "$dlist" variable becomes invalid at the time the control returns back to the first instance of the "show_dag" command and resulting in a "Cannot access memory at address 0x.." error message. How can I prevent this error? What other options are available to display nested class hierarchies in a neat way? (In case I'm moving towards a wrong direction:) Thanks, s.kopru