Add (utility) `GDBProcess >> gdbCommandParseAndValidate:`
to parse and validate given GDB command. This is used both by
`GDBLocalProcess` and settings UI.
--- a/GDBLocalProcess.st Thu Jun 13 08:05:30 2019 +0100
+++ b/GDBLocalProcess.st Tue Jun 18 11:04:46 2019 +0100
@@ -157,48 +157,22 @@
On error, thrown GDBError.
"
- | command argv exe |
+ | cmd |
commandOrNil isNil ifTrue:[
- command := self class gdbCommand.
- command isEmptyOrNil ifTrue:[
+ cmd := self class gdbCommand.
+ cmd isEmptyOrNil ifTrue:[
GDBError signal: 'GDB not found. Please set GDB command - `UserPreferences current gdbCommand:''...''`'.
^ nil.
].
] ifFalse:[
- command := commandOrNil.
- command isEmpty ifTrue:[
- GDBError signal: 'Command is empty'.
- ^ nil.
- ].
+ cmd := commandOrNil.
].
- argv := GDBShellCommandParser parse: command.
- exe := argv first.
- exe asFilename exists ifFalse:[
- "/ Try to find executable a long PATH, just as shell
- "/ would do...
- exe := OperatingSystem pathOfCommand: exe.
- exe notNil ifTrue:[
- argv at:1 put: exe.
- ] ifFalse:[
- GDBError signal: 'Command not found: ', argv first.
- ^ nil
- ].
- ] ifTrue:[
- "/ `exe` points to real file (or directory...), so
- "/ check here...
- exe := exe asFilename.
- exe isExecutable ifTrue:[
- argv at:1 put: exe asAbsoluteFilename pathName.
- ] ifFalse:[
- GDBError signal: 'Command not executable: ', argv first.
- ^ nil
- ].
- ].
- ^ argv
+ ^ self class gdbCommandParseAndValidate:cmd.
"Created: / 17-12-2018 / 10:48:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 18-06-2019 / 10:39:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
exited: status
@@ -219,3 +193,10 @@
"Created: / 27-03-2019 / 09:23:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
+!GDBLocalProcess class methodsFor:'documentation'!
+
+version_HG
+
+ ^ '$Changeset: <not expanded> $'
+! !
+
--- a/GDBProcess.st Thu Jun 13 08:05:30 2019 +0100
+++ b/GDBProcess.st Tue Jun 18 11:04:46 2019 +0100
@@ -91,7 +91,35 @@
| exe |
exe := UserPreferences current gdbCommand.
- exe notNil ifTrue:[ ^ exe ].
+ exe isNil ifTrue:[
+ exe := self gdbCommandDefault
+ ].
+ ^ exe
+
+ "
+ GDBProcess gdbCommand
+ UserPreferences current gdbCommand: nil.
+ UserPreferences current gdbCommand: '/home/jv/Projects/gdb/users_jv_vdb/gdb/gdb'.
+
+
+
+ "
+
+ "Created: / 13-12-2018 / 11:29:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 17-06-2019 / 14:21:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+gdbCommand: aString
+ UserPreferences current gdbCommand: aString
+
+ "Created: / 13-12-2018 / 11:29:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+gdbCommandDefault
+ "Return default path to `gdb` command or nil if no
+ suitable `gdb` executable is found"
+
+ | exe |
"/ On Windows, look for MSYS2 installation and
"/ try to pick GDB matching current arch (i686
@@ -125,13 +153,91 @@
"
- "Created: / 13-12-2018 / 11:29:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Created: / 17-06-2019 / 14:20:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
-gdbCommand: aString
- UserPreferences current gdbCommand: aString
+gdbCommandParseAndValidate:command
+ "Given a `command`, checks whether it is a valid gdb command.
+ Returns absolute path to gdb binary and global arguments (if any)
+ or raise an GDBError if `command` is not valid hg command."
+
+ | tokens executable executableAsFilename arguments version |
- "Created: / 13-12-2018 / 11:29:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ command isEmptyOrNil ifTrue:[
+ GDBError
+ raiseErrorString:('''gdb'' executable not configured and not found in standard places!!').
+ ^ nil
+ ].
+ command asFilename exists ifTrue:[
+ executable := command.
+ arguments := #().
+ ] ifFalse:[
+ tokens := GDBShellCommandParser parse:command.
+ executable := tokens first.
+ arguments := tokens copyFrom:2.
+ ].
+ executableAsFilename := executable asFilename.
+ executableAsFilename isAbsolute ifFalse:[
+ executableAsFilename := executableAsFilename asAbsoluteFilename.
+ executableAsFilename exists ifTrue:[
+ executable := executableAsFilename pathName.
+ ] ifFalse:[
+ "/ Also try to find specified command along PATH, maybe somebody
+ "/ just typed 'gdb' in...
+ executable := (OperatingSystem pathOfCommand:executable).
+ executable isNil ifTrue:[
+ GDBError
+ raiseErrorString:('''gdb'' executable (%1) not found!!' bindWith:command).
+ ^ nil
+ ] ifFalse:[
+ executableAsFilename := executable asFilename.
+ ].
+ ]
+ ].
+ executableAsFilename exists ifFalse:[
+ GDBError
+ raiseErrorString:('Specified ''gdb'' executable (%1) does not exists!!'
+ bindWith:executable).
+ ^ nil
+ ].
+ executableAsFilename isDirectory ifTrue:[
+ GDBError
+ raiseErrorString:('Specified ''gdb'' executable (%1) is actually a directory!!'
+ bindWith:executable).
+ ^ nil
+ ].
+ executableAsFilename isExecutable ifFalse:[
+ GDBError
+ raiseErrorString:('Specified ''gdb'' executable (%1) is cannot be executed!!'
+ bindWith:executable).
+ ^ nil
+ ].
+ "
+ [
+ version := self gdbVersionOf: executable arguments: arguments.
+ ] on: Error do:[:ex |
+ HGInvalidExecutableError newException
+ parameter: ex;
+ messageText: 'Failed to check version: ', ex description;
+ raise.
+ ^ nil
+ ].
+ (self gdbVersionIsSupported: version) ifFalse:[
+ HGInvalidVersionError newException
+ parameter: version;
+ messageText: ('Unsuported Mercurial version (%1)' bindWith: ((version collect:[:e|e printString]) asStringWith:$.));
+ raise.
+ ^ nil
+ ].
+ "
+ ^ (Array with:executable) , arguments
+
+ "
+ GDBProcess gdbCommand
+ GDBProcess gdbCommandValidate: 'gdb'
+ GDBProcess gdbCommandValidate: 'gdb -q'
+"
+ "Created: / 18-06-2019 / 10:26:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
gdbExecutable