public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* user defined function and passing types
@ 2010-09-10 14:41 Pawel K
  2010-09-10 15:59 ` Tom Tromey
  0 siblings, 1 reply; 2+ messages in thread
From: Pawel K @ 2010-09-10 14:41 UTC (permalink / raw)
  To: gdb

Hallo Group Members.

I have following user defined function:

define my_stl_list
  set $list = ($arg0)
  set $list_size = 0
  set $firstNode = $list._M_head
  set $curNode = $list._M_head._M_next
  while ($curNode != 0)
    printf "List Element %d: ", $list_size
    p ((const __gnu_cxx::_Slist_node<int> *)$curNode)->_M_data
    set $curNode = ($curNode)->_M_next
    set $list_size++
  end
end

As You can see, it displays contents of slist.
It's drawback is that it has hard coded type of list (const
__gnu_cxx::_Slist_node<int> *).
Is there a way to pass it as parameter to this macro?

best regards,
Pawel

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

* Re: user defined function and passing types
  2010-09-10 14:41 user defined function and passing types Pawel K
@ 2010-09-10 15:59 ` Tom Tromey
  0 siblings, 0 replies; 2+ messages in thread
From: Tom Tromey @ 2010-09-10 15:59 UTC (permalink / raw)
  To: Pawel K; +Cc: gdb

>>>>> "Pawel" == Pawel K <mafeusek@gmail.com> writes:

Pawel> I have following user defined function:
Pawel> define my_stl_list
[...]

Pawel> As You can see, it displays contents of slist.
Pawel> It's drawback is that it has hard coded type of list (const
Pawel> __gnu_cxx::_Slist_node<int> *).
Pawel> Is there a way to pass it as parameter to this macro?

What you really want is to use the new Python pretty-printing support.
We have a full suite of printers for libstdc++, checked into the
libstdc++ repository.  On a recent Linux distro, it will all "just work"
without manual intervention.

If you do need to set it up manually, there is some info here:

    http://sourceware.org/gdb/wiki/STLSupport


To answer your original question, there are two ways to do complicated
scripting things in gdb.

One is use the Python scripting support.  This is usually simplest, if
you can use it, because it is easy to do all kinds of string
manipulations and whatnot in Python.

The other is to use a gross GDB scripting trick: use "set logging" to
redirect output to a file; print things to that file; use "shell" plus a
shell script (or external perl or python or sed or whatever) to convert
that to a gdb script; then finally "source" the result.

Tom

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

end of thread, other threads:[~2010-09-10 15:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-09-10 14:41 user defined function and passing types Pawel K
2010-09-10 15:59 ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).