From: Jorge Gorbe Date: Mon, 29 Oct 2012 13:59:50 +0000 (+0100) Subject: changed viewer script to gtk/cairo/pango X-Git-Url: http://slack.codemaniacs.com/git/?a=commitdiff_plain;h=12c67fdbec73f05b75b5ed345bf36c006cab90a2;p=resacon2012.git changed viewer script to gtk/cairo/pango --- diff --git a/index.html b/index.html index c7761ae..44f6ee9 100644 --- a/index.html +++ b/index.html @@ -94,10 +94,13 @@ End with a line saying just "end". >end

I called this "Poor man's tracepoints" in a blog post some years ago

+

+ The cont there makes this workaround fail with single stepping (but this is solvable with Python, see + this blog post)

-

Custom commands (1/2)

+

Custom commands (1/3)

 (gdb) define plist
 Type commands for definition of "plist".
@@ -112,24 +115,81 @@ End with a line saying just "end".
 
-

Custom commands (2/2)

-

You can create hooks which run just before or after any gdb command:

-
+ +
+

Custom commands (3/3)

+

You can also create hooks which run just before or after any gdb command:

+
+
+

Python API

+
+ +
+
+ +
+
+ +
+
+

Did you know...?

GDB has many other semi-unknown cool features (which I won't talk about today)

+
+

Wish list

+

Other debuggers also have cool features

+ +
+
+

Resources

+

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

+
diff --git a/samples/script.py b/samples/script.py index d862955..b93f299 100644 --- a/samples/script.py +++ b/samples/script.py @@ -1,5 +1,6 @@ import gdb -from PyQt4 import QtGui +import gtk +import pangocairo def print_node(node, recursion_level): if len(node.type.fields()) == 0: @@ -19,6 +20,43 @@ def print_node(node, recursion_level): 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): @@ -28,11 +66,21 @@ class ViewerCommand(gdb.Command): 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) +