From 132a685299dd6d10bab9792fb2d67be029b8471b Mon Sep 17 00:00:00 2001 From: Jorge Gorbe Date: Fri, 9 Nov 2012 15:00:15 +0100 Subject: [PATCH] More slides --- slides/index.html | 141 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 119 insertions(+), 22 deletions(-) diff --git a/slides/index.html b/slides/index.html index 968388b..c504e9d 100644 --- a/slides/index.html +++ b/slides/index.html @@ -74,9 +74,21 @@

GDB is extensible

+
+ +
+

Extension points

+
@@ -178,32 +190,106 @@ Hello, World!

Pretty printing

-
+
+

Pretty printing

+

Friendly representation of your data structures

+
(gdb) p m
+$2 = std::map with 4 elements = {
+  ["blah"] = 2,
+  ["lolailo"] = 3,
+  ["trololo"] = 1,
+  ["xyz"] = 4
+}
+
+
+
+

Pretty printing

+

+ Up-to-date libc versions have pretty printers for STL containers. You don't need to do + anything to benefit from this RIGHT NOW. +

- - + +
+ +
+
+

Pretty printing

+

+ Of course, you can do it for your own data structures too: + Writing a pretty printer +

+
+ +
+

Pretty printer implementation

+

You need to define a class...

+
class StdStringPrinter(object):
+    "Print a std::string"
+     
+    def __init__(self, val):
+        self.val = val
+     
+    def to_string(self):
+        return self.val['_M_dataplus']['_M_p']
+     
+    def display_hint(self):
+        return 'string'
+
+
+ +
+

Pretty printer implementation

+

... and a lookup function

+
def str_lookup_function(val):
+    lookup_tag = val.type.tag
+    if lookup_tag == None:
+        return None
+    regex = re.compile("^std::basic_string$")
+    if regex.match(lookup_tag):
+        return StdStringPrinter(val)
+    return None
+
+

And then do some boring stuff to register it into gdb

+

Custom commands (python version)

-

+
 # create a class for your new command
 class DoNothingCommand(gdb.Command):
-    """This command does nothing."""  # docstring
+    """This command does nothing."""  # docstring (shown by gdb help command)
     def __init__(self):
-        super(DoNothingCommand, self).__init__("do_nothing", gdb.COMMAND_USER, gdb.COMPLETE_NONE)
-
+        super(DoNothingCommand, self).__init__("do_nothing",
+                                               gdb.COMMAND_USER,
+                                               gdb.COMPLETE_NONE)
     def invoke(self, arg, from_tty):
         pass
 
-DoNothingCommand()
+DoNothingCommand() # and instance it
 
 
@@ -223,15 +309,26 @@ DoNothingCommand()

Wish list

-

Other debuggers also have cool features

-
    -
  • Symbol server support

    records (some finite amount of) program history and allows backwards stepping/running.
  • +
      +
    • + Symbol and source server support
      + Central store for symbols of every build, so you can always retrieve the correct version automatically + without distributing debug info to users. Also, integration with SCM to retrieve the matching source code. + See Bruce Dawson's great post +

Resources

-

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

+
+ +
+

Thanks!

+

Questions?

-- 2.34.1