GDBCLICommand.st
author Jan Vrany <jan.vrany@labware.com>
Mon, 04 Sep 2023 14:00:57 +0100
changeset 314 4a2ef5a087f0
parent 306 76c3fe8614cc
permissions -rw-r--r--
Add MI parser test This commit add test to parse real-world frament which failed to Pharo properly at some point. It is encoded here as bytearray to make sure all the characters are preserved exactly as they were.

"
jv:libgdbs - GNU Debugger Interface Library
Copyright (C) 2015-now Jan Vrany
Copyright (C) 2022-2023 LabWare

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the 'Software'), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"
"{ Package: 'jv:libgdbs' }"

"{ NameSpace: Smalltalk }"

GDBCommand subclass:#GDBCLICommand
	instanceVariableNames:'value operation runOnBackground'
	classVariableNames:'Operations Aliases'
	poolDictionaries:''
	category:'GDB-Commands'
!

!GDBCLICommand class methodsFor:'documentation'!

copyright
"
jv:libgdbs - GNU Debugger Interface Library
Copyright (C) 2015-now Jan Vrany
Copyright (C) 2022-2023 LabWare

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the 'Software'), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"
! !

!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 newFromPairs: #( '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'
      findTokens: Character cr.

    "Created: / 28-01-2019 / 22:13:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 20-09-2022 / 17:38:29 / Jan Vrany <jan.vrany@labware.com>"
! !

!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 := 1.
        [ (value at: i) isSeparator ] whileFalse: [ i := i + 1 ].
        i <= value size ifTrue:[
            operation := value copyFrom: 1 to: 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 beginsWith: 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>"
    "Modified: / 12-07-2023 / 15:32:46 / Jan Vrany <jan.vrany@labware.com>"
!

runOnBackground
    ^ runOnBackground == true

    "Modified: / 28-01-2019 / 21:28:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

runOnBackground:aBoolean
    runOnBackground := aBoolean.
!

value
    ^ value
!

value:aString
    | i c |

    i := aString size.
    [ c := aString at: i. c isSeparator] whileTrue:[
        i := i - 1.
    ].
    c == $& ifTrue:[ 
        value := aString copyFrom: 1 to: i - 1.
        runOnBackground := true.
    ] ifFalse:[ 
        value := aString.
        runOnBackground := false.
    ].

    "Modified (format): / 28-01-2019 / 23:05:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 12-07-2023 / 15:30:12 / Jan Vrany <jan.vrany@labware.com>"
! !

!GDBCLICommand methodsFor:'testing'!

isCLICommand
    ^ true
! !

!GDBCLICommand class methodsFor:'documentation'!

version_HG

    ^ '$Changeset: <not expanded> $'
! !


GDBCLICommand initialize!