GDBCLICommand.st
changeset 174 18ef81a3fee5
parent 91 472a4841a8b6
child 259 651864c2aa29
--- a/GDBCLICommand.st	Mon Jan 28 14:56:14 2019 +0000
+++ b/GDBCLICommand.st	Mon Jan 28 22:47:57 2019 +0000
@@ -21,8 +21,8 @@
 "{ NameSpace: Smalltalk }"
 
 GDBCommand subclass:#GDBCLICommand
-	instanceVariableNames:'value runOnBackground'
-	classVariableNames:''
+	instanceVariableNames:'value operation runOnBackground'
+	classVariableNames:'Operations Aliases'
 	poolDictionaries:''
 	category:'GDB-Core-Commands'
 !
@@ -50,10 +50,291 @@
 "
 ! !
 
+!GDBCLICommand class methodsFor:'initialization'!
+
+initialize
+
+    " The string below is generated by:
+
+      gdb -ex 'set max-completions 1000000' -ex 'complete help ' -ex 'quit' | sed -e 's/^help //g'
+    "
+    Aliases := Dictionary withKeysAndValues: #(
+        'r'     'run'
+
+        'c'     'continue'
+        'fg'    'continue'
+
+        's'     'step'
+        'si'    'stepi'
+
+        'n'     'next'
+        'ni'    'nexti'
+
+        'u'     'until'    
+
+        'b'     'break'
+        ).
+
+    Operations := 
+'actions
+add-auto-load-safe-path
+add-auto-load-scripts-directory
+add-inferior
+add-symbol-file
+add-symbol-file-from-memory
+advance
+agent-printf
+alias
+aliases
+append
+apropos
+attach
+awatch
+backtrace
+bookmark
+break
+break-range
+breakpoints
+bt
+call
+catch
+cd
+checkpoint
+clear
+clone-inferior
+collect
+commands
+compare-sections
+compile
+complete
+condition
+continue
+core-file
+data
+define
+delete
+demangle
+detach
+directory
+disable
+disassemble
+disconnect
+display
+document
+dont-repeat
+down
+down-silently
+dprintf
+dump
+echo
+edit
+enable
+end
+eval
+exec-file
+explore
+expression
+faas
+file
+files
+find
+finish
+flash-erase
+flushregs
+focus
+forward-search
+frame
+fs
+ftrace
+function
+generate-core-file
+goto-bookmark
+guile
+guile-repl
+handle
+hbreak
+help
+if
+ignore
+inferior
+info
+init-if-undefined
+internals
+interpreter-exec
+interrupt
+jit-reader-load
+jit-reader-unload
+jump
+kill
+layout
+list
+load
+macro
+maintenance
+make
+mem
+monitor
+new-ui
+next
+nexti
+ni
+nosharedlibrary
+obscure
+output
+overlay
+passcount
+path
+print
+print-object
+printf
+ptype
+pwd
+python
+python-interactive
+queue-signal
+quit
+rbreak
+rc
+record
+refresh
+remote
+remove-inferiors
+remove-symbol-file
+restart
+restore
+return
+reverse-continue
+reverse-finish
+reverse-next
+reverse-nexti
+reverse-search
+reverse-step
+reverse-stepi
+rni
+rsi
+run
+running
+rwatch
+save
+search
+section
+select-frame
+set
+sharedlibrary
+shell
+show
+si
+signal
+skip
+source
+stack
+start
+starti
+status
+step
+stepi
+stepping
+stop
+strace
+support
+symbol-file
+taas
+tabset
+target
+task
+tbreak
+tcatch
+tdump
+teval
+tfaas
+tfind
+thbreak
+thread
+tp
+trace
+tracepoints
+tsave
+tstart
+tstatus
+tstop
+tty
+tui
+tvariable
+undisplay
+unset
+until
+up
+up-silently
+update
+user-defined
+watch
+wh
+whatis
+where
+while
+while-stepping
+winheight
+ws
+x'
+    splitBy: Character cr.
+
+    "Created: / 28-01-2019 / 22:13:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
 !GDBCLICommand methodsFor:'accessing'!
 
+operation
+    "The CLI command string without any arguments, such as 'run' , 'continue' 
+     and so on.
+
+     The resulting value expands all aliases, i.e., would return 'continue' even if
+     in the (user-typed) command it is just 'c' or 'cont'.
+
+     If there's no such CLI command, return nil. This may happen when user types
+     an ambiguous command and/or bogus command.
+
+     WARNING: This method uses static data, therefore may not reflect your GDB.
+     It does not reflect any commands defined by scripts.
+    "
+
+    operation isNil ifTrue:[ 
+        | i |
+
+        i := value indexOfSeparator.
+        i ~~ 0 ifTrue:[
+            operation := value copyTo: i - 1.
+        ] ifFalse:[ 
+            operation := value.
+        ].
+
+        (Aliases includesKey: operation) ifTrue:[ 
+            "/ If it is an alias, resolve it to it's canonical form
+            operation := Aliases at: operation
+        ] ifFalse:[ 
+            "/ else  handle 'shortened forms', i.e., for 'cont'
+            "/ return 'continue'
+            | candidates |
+
+            candidates := Operations select:[:e | e startsWith: operation ].
+            candidates size == 1 ifTrue:[ 
+                operation := candidates first
+            ] ifFalse:[ 
+                (candidates includes: operation) ifFalse:[ 
+                    operation := nil.
+                ].
+            ].
+        ].
+
+    ].
+    ^ operation
+
+    "Created: / 28-01-2019 / 21:49:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 runOnBackground
-    ^ runOnBackground
+    ^ runOnBackground == true
+
+    "Modified: / 28-01-2019 / 21:28:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 runOnBackground:aBoolean
@@ -65,7 +346,21 @@
 !
 
 value:aString
-    value := aString.
+    | i c |
+
+    i := aString size.
+    [ c := aString at: i. c isSeparator] whileTrue:[
+        i := i - 1.
+    ].
+    c == $& ifTrue:[ 
+        value := aString copyTo: i - 1.
+        runOnBackground := true.
+    ] ifFalse:[ 
+        value := aString.
+        runOnBackground := false.
+    ].
+
+    "Modified (format): / 28-01-2019 / 23:05:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !GDBCLICommand methodsFor:'testing'!
@@ -81,3 +376,5 @@
     ^ '$Changeset: <not expanded> $'
 ! !
 
+
+GDBCLICommand initialize!