Added #enablePrettyPrinting and #enableFrameFilters to allow Python scripts to augment presentation
authorJan Vrany <jan.vrany@fit.cvut.cz>
Mon, 12 Jun 2017 10:00:44 +0100
changeset 82 7ee72b7a498f
parent 81 5e07808d349f
child 83 b2fb8968f1f4
Added #enablePrettyPrinting and #enableFrameFilters to allow Python scripts to augment presentation Once enabled, it cannot be turned off - a limitation og GDB itself.
GDBCommandResult.st
GDBDebugger.st
GDBFrame.st
GDBVariable.st
--- a/GDBCommandResult.st	Tue Jun 06 09:37:04 2017 +0100
+++ b/GDBCommandResult.st	Mon Jun 12 10:00:44 2017 +0100
@@ -5,7 +5,7 @@
 GDBObject subclass:#GDBCommandResult
 	instanceVariableNames:'command status value'
 	classVariableNames:''
-	poolDictionaries:''
+	poolDictionaries:'GDBCommandStatus'
 	category:'GDB-Core-Commands'
 !
 
@@ -59,6 +59,20 @@
     "Modified: / 20-06-2014 / 09:05:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
+!GDBCommandResult methodsFor:'testing'!
+
+isDone
+    ^ status = CommandStatusDone
+
+    "Created: / 12-06-2017 / 09:36:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+isError
+    ^ status = CommandStatusError
+
+    "Created: / 12-06-2017 / 09:36:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
 !GDBCommandResult class methodsFor:'documentation'!
 
 version_HG
--- a/GDBDebugger.st	Tue Jun 06 09:37:04 2017 +0100
+++ b/GDBDebugger.st	Mon Jun 12 10:00:44 2017 +0100
@@ -4,7 +4,8 @@
 
 Object subclass:#GDBDebugger
 	instanceVariableNames:'connection commandSequenceNumber inferiorStateSequenceNumber
-		inferiors selectedInferior selectedThread selectedFrame'
+		inferiors selectedInferior selectedThread selectedFrame
+		prettyPrintingEnabled frameFiltersEnabled'
 	classVariableNames:''
 	poolDictionaries:'GDBCommandStatus'
 	category:'GDB-Core'
@@ -33,17 +34,6 @@
     "Created: / 02-06-2014 / 23:06:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
-attach: aStringOrInteger
-    "Attach to a running process.
-     API equivalent to CLI command:
-
-        (gdb) attach <aStringOrInteger>
-    "
-    self send:(GDBMI_target_attach arguments:{ aStringOrInteger asString }) andWait: true.
-
-    "Created: / 05-06-2017 / 17:08:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
 consoleInput
     ^ connection consoleInput
 
@@ -58,34 +48,6 @@
     "Modified: / 02-06-2017 / 23:13:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
-executable: aStringOrFilename
-    "Sets the executable to debug. 
-     API equivalent to CLI command:
-
-        (gdb) exec-file <aStringOrFilename>
-    "
-    self executable: aStringOrFilename arguments: nil
-
-    "Created: / 28-02-2015 / 00:19:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 05-06-2017 / 17:06:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-executable: aStringOrFilename arguments: anArray"of String"
-    "Sets the executable to debug and argument to pass to it.
-     API equivalent to CLI command:
-
-        (gdb) exec-file <aStringOrFilename>   
-        (gdb) set args <anArray>
-    "
-
-    self send:(GDBMI_file_exec_and_symbols arguments:{ aStringOrFilename asString }) andWait: true.
-    anArray notEmptyOrNil ifTrue:[ 
-        self send: (GDBMI_exec_arguments arguments: anArray) andWait: true.
-    ].
-
-    "Created: / 05-06-2017 / 17:05:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
 inferiorForId: id
     ^ inferiors ? #() detect:[:e | e id = id ] ifNone:[ 
         self error: ('No inferior (thread group) with id ''%1'' found!!' bindWith: id)
@@ -280,7 +242,82 @@
     "Modified: / 08-03-2015 / 07:31:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
-!GDBDebugger methodsFor:'commands-convenience'!
+!GDBDebugger methodsFor:'commands - API'!
+
+attach: aStringOrInteger
+    "Attach to a running process.
+     API equivalent to CLI command:
+
+        (gdb) attach <aStringOrInteger>
+    "
+    self send:(GDBMI_target_attach arguments:{ aStringOrInteger asString }) andWait: true.
+
+    "Created: / 05-06-2017 / 17:08:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+enableFrameFilters
+    "Enables frame filters & frame decorators for MI interface. Once enabled,
+     cannot be turned off.
+
+     @see GDBMI_enable_frame_filters"
+
+    | result |
+    result := self send: GDBMI_enable_frame_filters new.
+    result isDone ifTrue:[ 
+        frameFiltersEnabled := true.
+    ] ifFalse:[ 
+        GDBError raiseErrorString: 'failed to enable frame filters'
+    ].
+
+    "Created: / 12-06-2017 / 09:29:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+enablePrettyPrinting
+    "Enables pretty printing for MI interface. Once enabled,
+     cannot be turned off.
+
+     @see GDBMI_enable_pretty_printing"
+
+    | result |
+    result := self send: GDBMI_enable_pretty_printing new.
+    result isDone ifTrue:[ 
+        prettyPrintingEnabled := true.
+    ] ifFalse:[ 
+        GDBError raiseErrorString: 'failed to enable pretty printing'
+    ].
+
+    "Created: / 12-06-2017 / 09:29:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+executable: aStringOrFilename
+    "Sets the executable to debug. 
+     API equivalent to CLI command:
+
+        (gdb) exec-file <aStringOrFilename>
+    "
+    self executable: aStringOrFilename arguments: nil
+
+    "Created: / 28-02-2015 / 00:19:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 05-06-2017 / 17:06:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+executable: aStringOrFilename arguments: anArray"of String"
+    "Sets the executable to debug and argument to pass to it.
+     API equivalent to CLI command:
+
+        (gdb) exec-file <aStringOrFilename>   
+        (gdb) set args <anArray>
+    "
+
+    self send:(GDBMI_file_exec_and_symbols arguments:{ aStringOrFilename asString }) andWait: true.
+    anArray notEmptyOrNil ifTrue:[ 
+        self send: (GDBMI_exec_arguments arguments: anArray) andWait: true.
+    ].
+
+    "Created: / 05-06-2017 / 17:05:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!GDBDebugger methodsFor:'evaluating'!
 
 do: block andWaitFor:eventHandlers
     "Evaluates a given block and then wait for events.
@@ -293,12 +330,13 @@
                     - If event class, then wait for an event of that class. Note, that
                       subclasses are handled too.
                     - If block, then wait for an event for which the block returns true.
-                    - If collectio, then wait for a sequence of events, each matched as above.
+                    - If collection, then wait for a sequence of events, each matched as above.
      Returns:       a matching event or events (in case a collection of handlers has been passed)"
 
     ^ self do: block andWaitFor: eventHandlers withTimeoutMs: nil
 
     "Created: / 08-03-2015 / 07:30:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified (comment): / 12-06-2017 / 09:31:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 do: block andWaitFor:eventHandlers withTimeoutMs:timeout 
@@ -522,8 +560,11 @@
     self send: (GDBMI_inferior_tty_set arguments: { connection inferiorPTY name }).
     self send: (GDBMI_gdb_set arguments: #('target-async' 'on')).
 
+    prettyPrintingEnabled := false.
+    frameFiltersEnabled := false.
+
     "Created: / 20-06-2014 / 21:45:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 29-09-2014 / 23:30:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 12-06-2017 / 09:49:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 release
@@ -568,6 +609,18 @@
     ^ connection notNil
 
     "Created: / 20-06-2014 / 22:12:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+isFrameFiltersEnabled
+    ^ frameFiltersEnabled
+
+    "Created: / 12-06-2017 / 09:41:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+isPrettyPrintingEnabled
+    ^ prettyPrintingEnabled
+
+    "Created: / 12-06-2017 / 09:40:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !GDBDebugger class methodsFor:'documentation'!
--- a/GDBFrame.st	Tue Jun 06 09:37:04 2017 +0100
+++ b/GDBFrame.st	Mon Jun 12 10:00:44 2017 +0100
@@ -33,7 +33,10 @@
 !
 
 file
-    ^ file
+    "Return filename containing frame's function source."
+    ^ fullname notNil ifTrue:[ fullname ] ifFalse:[ file ]
+
+    "Modified: / 11-06-2017 / 20:59:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 from
@@ -82,19 +85,31 @@
 
 displayString
     ^ String streamContents: [ :aStream |
+        | f |
+
+        f := self file.
         level printOn:aStream base: 10 size: 2 fill: Character space.
         aStream nextPutAll:' '.
         addr printOn:aStream.
         aStream nextPutAll:' '.
-        func printOn:aStream.
-        aStream nextPutAll:' ('.
-        file printOn:aStream.
-        aStream nextPutAll:', line: '.
-        line printOn:aStream.
-        aStream nextPutAll:')'.
+        func notNil ifTrue:[
+            func printOn:aStream.
+        ] ifFalse:[ 
+            aStream nextPutAll: '?'
+        ].
+        f notNil ifTrue:[
+            aStream nextPutAll:' ('.
+            aStream nextPutAll: f startingAt: (f lastIndexOf: Filename separator) + 1.
+            line notNil ifTrue:[
+                aStream nextPutAll:':'.
+                line printOn:aStream.
+            ].
+            aStream nextPutAll:')'.
+        ].
     ].
 
     "Created: / 27-02-2015 / 15:20:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 12-06-2017 / 09:04:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 printOn:aStream
--- a/GDBVariable.st	Tue Jun 06 09:37:04 2017 +0100
+++ b/GDBVariable.st	Mon Jun 12 10:00:44 2017 +0100
@@ -95,6 +95,21 @@
     aStream nextPutAll:')'.
 
     "Modified: / 27-02-2015 / 15:18:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+valueString
+    "Return value as string to be presented to user. The difference
+     to sending `value displayString` is that #valueString returns a
+     pretty-printed value (if pretty printing was enabled for GDB)
+
+     @see GDBMI_enable_pretty_printing
+     @see GDBDebugger >> enablePrettyPrinting
+    "
+
+    ^ value notNil ifTrue:[ value ] ifFalse:[ self value displayString ]
+
+    "Created: / 11-06-2017 / 23:24:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified (comment): / 12-06-2017 / 09:26:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !GDBVariable class methodsFor:'documentation'!