GDBCLICommand.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Mon, 08 Jul 2019 10:58:09 +0100
changeset 199 cb411138b295
parent 174 18ef81a3fee5
child 259 651864c2aa29
permissions -rw-r--r--
Send CLI commands using `-interpreter-exec` ...rather than sendinmg them bare. The problem is with C-escaping, apparently some commands need C-style escaping while others do not. This should fix the problem for good, will see.

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

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License. 

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
"
"{ Package: 'jv:libgdbs' }"

"{ NameSpace: Smalltalk }"

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

!GDBCLICommand class methodsFor:'documentation'!

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

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License. 

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
"
! !

!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 == 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 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'!

isCLICommand
    ^ true
! !

!GDBCLICommand class methodsFor:'documentation'!

version_HG

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


GDBCLICommand initialize!