Mirror of the gdb mailing list
 help / color / mirror / Atom feed
* recursive user-defined commands and
@ 2009-08-12 23:10 Selcuk Kopru
  2009-08-13 15:59 ` Tom Tromey
  0 siblings, 1 reply; 6+ messages in thread
From: Selcuk Kopru @ 2009-08-12 23:10 UTC (permalink / raw)
  To: gdb

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




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2009-09-09 22:38 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-08-12 23:10 recursive user-defined commands and Selcuk Kopru
2009-08-13 15:59 ` Tom Tromey
2009-09-04 19:29   ` Selcuk Kopru
2009-09-04 19:31     ` Tom Tromey
2009-09-05  0:13       ` Selcuk Kopru
2009-09-09 22:38         ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox