>end
</pre>
<p>I called this <a href="http://slackito.com/2011/12/09/poor-mans-tracepoints-with-gdb/">"Poor man's tracepoints"</a> in a blog post some years ago</p>
+<p class="slide">
+ The <code>cont</code> there makes this workaround fail with single stepping (but this is solvable with Python, see
+ <a href="http://tromey.com/blog/?p=698">this blog post</a>)
</section>
<section class="slide">
- <h2> Custom commands (1/2) </h2>
+ <h2> Custom commands (1/3) </h2>
<pre>
(gdb) define plist
Type commands for definition of "plist".
</section>
<section class="slide">
- <h2> Custom commands (2/2) </h2>
- <p> You can create hooks which run just before or after any gdb command: </p>
- <ul style="text-align:left;">
- <li> <code>define hook-command</code> to run things <b>before</b> <code>command</code> </li>
- <li> <code>define hookpost-command</code> to run things <b>after</b> <code>command</code> </li>
+<h2> Custom commands (2/3) </h2>
+<p>A more complex example, from PpluX's <a href="http://code.google.com/p/slb/source/browse/extra/lua_utils.gdb?name=default">SLB repo</a></p>
+
+<pre>
+define luastack
+ set $top = lua_gettop($arg0)
+ set $i = 1
+ while $i <= $top
+ if lua_type($arg0,$i) == -1
+ printf "stack - %i : No Value \n", $i
+ else
+ call lua_pushvalue($arg0,$i)
+ set $str = lua_tolstring($arg0,-1,0x0)
+ set $type = lua_typename($arg0,lua_type($arg0,$i))
+ if $str
+ printf "stack - %i : %s -> '%s'\n", $i, $type , $str
+ else
+ printf "stack - %i : %s\n", $i, $type
+ end
+ call lua_settop($arg0,-2)
+ end
+ set $i = $i + 1
+ end
+</pre>
+
+</section>
+
+<section class="slide">
+ <h2> Custom commands (3/3) </h2>
+ <p> You can also create hooks which run just before or after any gdb command: </p>
+ <ul style="text-align:left;">
+ <li> <code>define hook-command</code> to run things <b>before</b> <code>command</code> </li>
+ <li> <code>define hookpost-command</code> to run things <b>after</b> <code>command</code> </li>
</section>
+<section class="slide">
+<h2> Python API </h2>
+<ul>
+ <li> Available since GDB 7 </li>
+ <li> Still being refined </li>
+
+</section>
+
+<section class="slide">
+</section>
+
+<section class="slide">
+</section>
+
+<section class="slide">
+</section>
+
<section class="slide">
<h2>Did you know...?</h2>
<p> GDB has many other semi-unknown cool features (which I won't talk about today) </p>
<ul style="text-align:left;">
- <li class="slide"> <h3>Reverse debugging</h3> records (some finite amount of) program history and allows backwards stepping/running. </li>
+ <li class="slide"> <h3>Debug info in external files</h3> You can move debug info from compiled objects and point gdb to it (like PDBs in VS)</li>
+ <li class="slide"> <h3>Reverse debugging</h3> Records (some finite amount of) program history and allows backwards stepping/running. </li>
<li class="slide"> <h3>JIT interface</h3>a JIT can generate debug symbols and pass them on-the-fly to gdb to ease debugging (supported by LLVM!). </li>
</ul>
</section>
+<section class="slide">
+ <h2>Wish list</h2>
+ <p>Other debuggers also have cool features</p>
+ <ul style="text-align:left;">
+ <li class="slide"> <h3>Symbol server support</h3> records (some finite amount of) program history and allows backwards stepping/running. </li>
+ </ul>
+</section>
+<section class="slide">
+ <h2>Resources</h2>
+ <p> <a href="http://sourceware.org/gdb/wiki/PythonGdbTutorial">http://sourceware.org/gdb/wiki/PythonGdbTutorial</a> </p>
+</section>
<!-- End slides. -->
import gdb
-from PyQt4 import QtGui
+import gtk
+import pangocairo
def print_node(node, recursion_level):
if len(node.type.fields()) == 0:
result[f.name] = result_child
return result
+
+
+class GraphViewer(gtk.DrawingArea):
+ def __init__(self):
+ super(gtk.DrawingArea, self).__init__()
+ self.connect("expose_event", self.expose)
+
+ def expose(self, widget, event):
+ context = widget.window.cairo_create()
+ context.rectangle(event.area.x, event.area.y, event.area.width, event.area.height)
+ context.clip()
+ self.draw(context)
+ return False
+
+ def draw(self, context):
+ rect = self.get_allocation() # widget dimensions?
+
+ pangocairo_context = pangocairo.CairoContext(context)
+ layout = pangocairo_context.create_layout()
+ layout.set_text("Trololol")
+ context.move_to(100,100)
+ pangocairo_context.show_layout(layout)
+
+
+ #context.set_source_rgb(1.0, 0.0, 0.0)
+ context.move_to(0,0)
+ context.line_to(200,100)
+ context.set_line_width(4)
+ context.stroke()
+
+ context.rectangle(200,200,50,50)
+ context.set_line_width(1)
+ context.stroke()
+
+
+
+
class ViewerCommand(gdb.Command):
"""View data structures"""
def __init__(self):
def invoke(self, arg, from_tty):
args = gdb.string_to_argv(arg)
value = gdb.parse_and_eval(args[0])
- if len(args) > 1:
- recursion_level = int(args[1])
- else:
- recursion_level = 3
- print print_node(value.dereference(), recursion_level)
+
+ window = gtk.Window()
+ viewer = GraphViewer()
+ window.add(viewer)
+ window.connect("destroy", gtk.main_quit)
+ window.set_default_size(600,600)
+ window.show_all()
+ gtk.main()
+
+ #if len(args) > 1:
+ # recursion_level = int(args[1])
+ #else:
+ # recursion_level = 3
+ #print print_node(value.dereference(), recursion_level)
+