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

* Re: recursive user-defined commands and
  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
  0 siblings, 1 reply; 6+ messages in thread
From: Tom Tromey @ 2009-08-13 15:59 UTC (permalink / raw)
  To: selcuk.kopru; +Cc: gdb

>>>>> ">" == Selcuk Kopru <selcuk.kopru@tyazilimevi.com> writes:

>> I'm trying to write user-defined commands to view some
>> nested/embedded classes which form a huge data hierarchy.

My advice is to switch to CVS GDB and use the new Python-based
pretty-printing feature.

With this feature you can write Python code to customize the display of
various objects in your program.  This is mostly transparent to the user
-- "print" will print them prettily, so will stack traces, so will MI
(soon), etc.

>> define show_string
>> 	wchar_print ((CMyString*)$arg0).m_Value
>> end

CVS GDB also has direct support for wide characters.

>> 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?

I suppose you could allocate an array and then manage the recursion
manually by using $dlist[$depth].

Otherwise, yeah, this seems like a limitation of gdb's scripting
language.  It seems like it would nice to let user-defined commands
define local variables.

Tom


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

* Re: recursive user-defined commands and
  2009-08-13 15:59 ` Tom Tromey
@ 2009-09-04 19:29   ` Selcuk Kopru
  2009-09-04 19:31     ` Tom Tromey
  0 siblings, 1 reply; 6+ messages in thread
From: Selcuk Kopru @ 2009-09-04 19:29 UTC (permalink / raw)
  To: gdb

Hi,

A late follow-up question:

How can we allocate an array type convenience variable?

Using $dlist[$depth] without any prior declaration results in the
following error:

"cannot subscript something of type `void'"

Regards,
selcuk

On Thu, 2009-08-13 at 09:59 -0600, Tom Tromey wrote:
> >>>>> ">" == Selcuk Kopru <selcuk.kopru@tyazilimevi.com> writes:
> 
> >> I'm trying to write user-defined commands to view some
> >> nested/embedded classes which form a huge data hierarchy.
> 
> My advice is to switch to CVS GDB and use the new Python-based
> pretty-printing feature.
> 
> With this feature you can write Python code to customize the display of
> various objects in your program.  This is mostly transparent to the user
> -- "print" will print them prettily, so will stack traces, so will MI
> (soon), etc.
> 
> >> define show_string
> >> 	wchar_print ((CMyString*)$arg0).m_Value
> >> end
> 
> CVS GDB also has direct support for wide characters.
> 
> >> 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?
> 
> I suppose you could allocate an array and then manage the recursion
> manually by using $dlist[$depth].
> 
> Otherwise, yeah, this seems like a limitation of gdb's scripting
> language.  It seems like it would nice to let user-defined commands
> define local variables.
> 
> Tom


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

* Re: recursive user-defined commands and
  2009-09-04 19:29   ` Selcuk Kopru
@ 2009-09-04 19:31     ` Tom Tromey
  2009-09-05  0:13       ` Selcuk Kopru
  0 siblings, 1 reply; 6+ messages in thread
From: Tom Tromey @ 2009-09-04 19:31 UTC (permalink / raw)
  To: selcuk.kopru; +Cc: gdb

>>>>> ">" == Selcuk Kopru <selcuk.kopru@tyazilimevi.com> writes:

>> How can we allocate an array type convenience variable?

set variable $var = (type *) malloc (count * sizeof (type))

Tom


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

* Re: recursive user-defined commands and
  2009-09-04 19:31     ` Tom Tromey
@ 2009-09-05  0:13       ` Selcuk Kopru
  2009-09-09 22:38         ` Tom Tromey
  0 siblings, 1 reply; 6+ messages in thread
From: Selcuk Kopru @ 2009-09-05  0:13 UTC (permalink / raw)
  To: gdb

Hi,

Thanks for the reply. I'm making progress but was not able to solve the
problem yet. The following 3 examples didn't work, all giving "A syntax
error in expression, near `)malloc(..." message:

1) set variable $myvar = (List<CLECSFeatValue>::LNode**)malloc(10 *
sizeof(List<CLECSFeatValue>::LNode*))

2) set variable $myvar = (List<CLECSFeatValue>::LNode*)malloc(10 *
sizeof(List<CLECSFeatValue>::LNode))

3) set variable $myvar = ((struct
List<CLECSFeatValue>::LNode)*)malloc(10 *
sizeof(List<CLECSFeatValue>::LNode))

The following 2 commands work as expected.
4) p sizeof(struct List<CLECSFeatValue>::LNode)
$81 = 12
5) p sizeof(List<CLECSFeatValue>::LNode)
$81 = 12

But the following do not work even if I put parentheses everywhere.
6) p sizeof(struct List<CLECSFeatValue>::LNode*)
7) p sizeof(List<CLECSFeatValue>::LNode*)

Using void* didn't help as it wasn't possible to cast to the LNode*
type.

Thanks,
selcuk

On Fri, 2009-09-04 at 13:31 -0600, Tom Tromey wrote: 
> >>>>> ">" == Selcuk Kopru <selcuk.kopru@tyazilimevi.com> writes:
> 
> >> How can we allocate an array type convenience variable?
> 
> set variable $var = (type *) malloc (count * sizeof (type))
> 
> Tom


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

* Re: recursive user-defined commands and
  2009-09-05  0:13       ` Selcuk Kopru
@ 2009-09-09 22:38         ` Tom Tromey
  0 siblings, 0 replies; 6+ messages in thread
From: Tom Tromey @ 2009-09-09 22:38 UTC (permalink / raw)
  To: selcuk.kopru; +Cc: gdb

>>>>> "Selcuk" == Selcuk Kopru <selcuk.kopru@tyazilimevi.com> writes:

Selcuk> Thanks for the reply. I'm making progress but was not able to
Selcuk> solve the problem yet. The following 3 examples didn't work, all
Selcuk> giving "A syntax error in expression, near `)malloc(..."
Selcuk> message:
Selcuk> 1) set variable $myvar = (List<CLECSFeatValue>::LNode**)malloc(10 *
Selcuk> sizeof(List<CLECSFeatValue>::LNode*))

Yes, casts with qualified types often do not work.  This is a bug in
GDB.

Sometimes putting single quotes around the type helps.

FWIW, I believe Keith has basically killed this bug on his branch in the
archer repository.  He's submitting this patch series now.

Tom


^ 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