application/VDBStartup.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Thu, 23 Nov 2017 22:45:57 +0000
changeset 49 2ec7f7ed9242
parent 47 25d82943a3cf
child 83 101ff2210613
permissions -rw-r--r--
License this package under 'Creative Commons Attribution-NonCommercial 4.0 International License'
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
49
2ec7f7ed9242 License this package under 'Creative Commons Attribution-NonCommercial 4.0 International License'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 47
diff changeset
     1
"
2ec7f7ed9242 License this package under 'Creative Commons Attribution-NonCommercial 4.0 International License'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 47
diff changeset
     2
jv:vdb - Visual / VM Debugger
2ec7f7ed9242 License this package under 'Creative Commons Attribution-NonCommercial 4.0 International License'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 47
diff changeset
     3
Copyright (C) 2015-now Jan Vrany
2ec7f7ed9242 License this package under 'Creative Commons Attribution-NonCommercial 4.0 International License'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 47
diff changeset
     4
2ec7f7ed9242 License this package under 'Creative Commons Attribution-NonCommercial 4.0 International License'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 47
diff changeset
     5
This software is licensed under 'Creative Commons Attribution-NonCommercial 4.0 International License'
2ec7f7ed9242 License this package under 'Creative Commons Attribution-NonCommercial 4.0 International License'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 47
diff changeset
     6
2ec7f7ed9242 License this package under 'Creative Commons Attribution-NonCommercial 4.0 International License'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 47
diff changeset
     7
You may find a full license text in LICENSE.txt or at http://creativecommons.org/licenses/by-nc/4.0/
2ec7f7ed9242 License this package under 'Creative Commons Attribution-NonCommercial 4.0 International License'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 47
diff changeset
     8
"
18
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     9
"{ Package: 'jv:vdb/application' }"
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    10
37
f417fe8685c5 Initial support for variables
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18
diff changeset
    11
"{ NameSpace: Smalltalk }"
f417fe8685c5 Initial support for variables
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18
diff changeset
    12
18
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    13
StandaloneStartup subclass:#VDBStartup
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    14
	instanceVariableNames:''
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    15
	classVariableNames:''
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    16
	poolDictionaries:''
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    17
	category:'VDB-UI'
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    18
!
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    19
49
2ec7f7ed9242 License this package under 'Creative Commons Attribution-NonCommercial 4.0 International License'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 47
diff changeset
    20
!VDBStartup class methodsFor:'documentation'!
2ec7f7ed9242 License this package under 'Creative Commons Attribution-NonCommercial 4.0 International License'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 47
diff changeset
    21
2ec7f7ed9242 License this package under 'Creative Commons Attribution-NonCommercial 4.0 International License'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 47
diff changeset
    22
copyright
2ec7f7ed9242 License this package under 'Creative Commons Attribution-NonCommercial 4.0 International License'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 47
diff changeset
    23
"
2ec7f7ed9242 License this package under 'Creative Commons Attribution-NonCommercial 4.0 International License'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 47
diff changeset
    24
jv:vdb - Visual / VM Debugger
2ec7f7ed9242 License this package under 'Creative Commons Attribution-NonCommercial 4.0 International License'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 47
diff changeset
    25
Copyright (C) 2015-now Jan Vrany
2ec7f7ed9242 License this package under 'Creative Commons Attribution-NonCommercial 4.0 International License'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 47
diff changeset
    26
2ec7f7ed9242 License this package under 'Creative Commons Attribution-NonCommercial 4.0 International License'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 47
diff changeset
    27
This software is licensed under 'Creative Commons Attribution-NonCommercial 4.0 International License'
2ec7f7ed9242 License this package under 'Creative Commons Attribution-NonCommercial 4.0 International License'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 47
diff changeset
    28
2ec7f7ed9242 License this package under 'Creative Commons Attribution-NonCommercial 4.0 International License'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 47
diff changeset
    29
You may find a full license text in LICENSE.txt or at http://creativecommons.org/licenses/by-nc/4.0/
2ec7f7ed9242 License this package under 'Creative Commons Attribution-NonCommercial 4.0 International License'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 47
diff changeset
    30
"
2ec7f7ed9242 License this package under 'Creative Commons Attribution-NonCommercial 4.0 International License'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 47
diff changeset
    31
! !
18
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    32
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    33
!VDBStartup class methodsFor:'constants & defaults'!
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    34
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    35
applicationRegistryPath
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    36
    "the key under which this application stores its process ID in the registry
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    37
     as a collection of path-components.
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    38
     i.e. if #('foo' 'bar' 'baz') is returned here, the current applications ID will be stored
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    39
     in HKEY_CURRENT_USER\Software\foo\bar\baz\CurrentID.
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    40
     (would also be used as a relative path for a temporary lock file under unix).
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    41
     Used to detect if another instance of this application is already running."
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    42
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    43
    ^ #('vdb')
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    44
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    45
    "Modified: / 21-09-2014 / 01:29:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    46
!
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    47
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    48
applicationUUID
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    49
    "answer an application-specific unique uuid.
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    50
     This is used as the name of some exclusive OS-resource, which is used to find out,
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    51
     if another instance of this application is already running.
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    52
     Under win32, a mutex is used; under unix, an exclusive file in the tempDir could be used.
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    53
     If redefined, please return a real UUID (i.e. UUID fromString:'.....') and not a string or
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    54
     similar possibly conflicting identifier.
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    55
     You can paste a fresh worldwide unique id via the editor's more-misc-paste UUID menuFunction."
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    56
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    57
    ^ UUID fromString:'57b09330-4126-11e4-a80f-606720e43e2c'
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    58
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    59
    "Modified: / 21-09-2014 / 01:29:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    60
! !
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    61
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    62
!VDBStartup class methodsFor:'defaults'!
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    63
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    64
allowDebugOption
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    65
    "enable/disable the --debug startup option.
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    66
     Can be redefined in subclasses to enable it"
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    67
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    68
    ^ true
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    69
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    70
    "Created: / 08-09-2014 / 19:30:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    71
! !
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    72
43
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
    73
!VDBStartup class methodsFor:'private'!
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
    74
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
    75
loadPreferenceFile: file
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
    76
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
    77
    "Created: / 07-06-2017 / 09:49:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
    78
! !
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
    79
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
    80
!VDBStartup class methodsFor:'queries'!
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
    81
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
    82
applicationName
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
    83
    ^ 'vdb'
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
    84
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
    85
    "Created: / 06-06-2017 / 22:50:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
    86
! !
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
    87
18
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    88
!VDBStartup class methodsFor:'startup'!
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    89
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    90
main:argv
43
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
    91
    "Application entry point. `argv` is the array of command arguments (as Array of Strings)"
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
    92
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
    93
    | optparser positional settingsFile settingsSuppressed programExecutable programArgs programPid attach debugger |
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
    94
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
    95
    settingsSuppressed := false.
47
25d82943a3cf Allow VDB to be launched without PID or program to debug
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 43
diff changeset
    96
    attach := false.
43
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
    97
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
    98
    "/ Parse options...
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
    99
    optparser := CmdLineParser new
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
   100
                    ignoreUnknownOptions: true;
47
25d82943a3cf Allow VDB to be launched without PID or program to debug
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 43
diff changeset
   101
                    on: #('--help') do:[
25d82943a3cf Allow VDB to be launched without PID or program to debug
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 43
diff changeset
   102
                        self usage
43
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
   103
                    ];
47
25d82943a3cf Allow VDB to be launched without PID or program to debug
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 43
diff changeset
   104
                    on: #('--preferences') do:[:filename |
43
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
   105
                        | file |
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
   106
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
   107
                        file := filename asFilename.
47
25d82943a3cf Allow VDB to be launched without PID or program to debug
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 43
diff changeset
   108
                        file isReadable ifFalse:[
43
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
   109
                            self error: 'preference file does not exists or not readable: ' , filename.
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
   110
                        ].
47
25d82943a3cf Allow VDB to be launched without PID or program to debug
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 43
diff changeset
   111
                        file isRegularFile ifFalse:[
43
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
   112
                            self error: 'preference file is not a regular file: ' , filename.
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
   113
                        ].
47
25d82943a3cf Allow VDB to be launched without PID or program to debug
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 43
diff changeset
   114
                        settingsFile := file.
43
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
   115
                    ];
47
25d82943a3cf Allow VDB to be launched without PID or program to debug
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 43
diff changeset
   116
                    on: #('--no-preferences') do:[
25d82943a3cf Allow VDB to be launched without PID or program to debug
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 43
diff changeset
   117
                        settingsSuppressed := true
43
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
   118
                    ];
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
   119
                    yourself.
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
   120
    [
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
   121
        positional := optparser parse:argv.
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
   122
    ] on: CmdLineOptionError do:[:ex |
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
   123
        self error: ex description.
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
   124
    ].
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
   125
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
   126
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
   127
    "/ Now validate and process options
47
25d82943a3cf Allow VDB to be launched without PID or program to debug
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 43
diff changeset
   128
    settingsSuppressed ifFalse:[
43
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
   129
        | settings |
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
   130
47
25d82943a3cf Allow VDB to be launched without PID or program to debug
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 43
diff changeset
   131
        settingsFile notNil ifTrue:[
43
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
   132
            settingsFile exists ifFalse:[
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
   133
                self error: 'preference file does not exist: ', settingsFile pathName
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
   134
            ].
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
   135
            settingsFile isDirectory ifTrue:[
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
   136
                self error: 'preference file is not a regular file: ', settingsFile pathName
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
   137
            ].
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
   138
            settingsFile isReadable ifFalse:[
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
   139
                self error: 'preference file is not a readable (check permissions): ', settingsFile pathName
47
25d82943a3cf Allow VDB to be launched without PID or program to debug
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 43
diff changeset
   140
            ].
25d82943a3cf Allow VDB to be launched without PID or program to debug
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 43
diff changeset
   141
            settings := UserPreferences loadSettingsFrom: settingsFile.
25d82943a3cf Allow VDB to be launched without PID or program to debug
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 43
diff changeset
   142
        ] ifFalse:[
43
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
   143
            settings := UserPreferences loadSettings.
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
   144
        ].
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
   145
        UserPreferences setCurrent: settings.
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
   146
    ].
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
   147
47
25d82943a3cf Allow VDB to be launched without PID or program to debug
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 43
diff changeset
   148
    "/ Parse positional arguments - there are two forms:
25d82943a3cf Allow VDB to be launched without PID or program to debug
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 43
diff changeset
   149
    "/
25d82943a3cf Allow VDB to be launched without PID or program to debug
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 43
diff changeset
   150
    "/   vdb [OPTIONS] [PROGRAM [ARGS]]
25d82943a3cf Allow VDB to be launched without PID or program to debug
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 43
diff changeset
   151
    "/   vdb [OPTIONS] [PID]
25d82943a3cf Allow VDB to be launched without PID or program to debug
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 43
diff changeset
   152
    "/
25d82943a3cf Allow VDB to be launched without PID or program to debug
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 43
diff changeset
   153
    "/ [OPTIONS] have already been processed, the rest is in `positional`
25d82943a3cf Allow VDB to be launched without PID or program to debug
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 43
diff changeset
   154
    "/ variable
25d82943a3cf Allow VDB to be launched without PID or program to debug
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 43
diff changeset
   155
25d82943a3cf Allow VDB to be launched without PID or program to debug
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 43
diff changeset
   156
    positional notEmpty ifTrue:[
25d82943a3cf Allow VDB to be launched without PID or program to debug
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 43
diff changeset
   157
        programExecutable := positional first.
25d82943a3cf Allow VDB to be launched without PID or program to debug
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 43
diff changeset
   158
        programExecutable asFilename exists ifFalse:[
25d82943a3cf Allow VDB to be launched without PID or program to debug
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 43
diff changeset
   159
            programExecutable := OperatingSystem pathOfCommand: programExecutable.
25d82943a3cf Allow VDB to be launched without PID or program to debug
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 43
diff changeset
   160
        ].
25d82943a3cf Allow VDB to be launched without PID or program to debug
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 43
diff changeset
   161
        programPid := Integer fromString: positional first onError: [ nil ].
25d82943a3cf Allow VDB to be launched without PID or program to debug
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 43
diff changeset
   162
        programArgs := positional copyFrom: 2.
25d82943a3cf Allow VDB to be launched without PID or program to debug
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 43
diff changeset
   163
25d82943a3cf Allow VDB to be launched without PID or program to debug
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 43
diff changeset
   164
        "/ If * programExecutable does not exists
25d82943a3cf Allow VDB to be launched without PID or program to debug
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 43
diff changeset
   165
        "/    * AND programPid is not nil (i.e., first positional argument can be converted to an integer)
25d82943a3cf Allow VDB to be launched without PID or program to debug
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 43
diff changeset
   166
        "/    * AND programArguments are empty
25d82943a3cf Allow VDB to be launched without PID or program to debug
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 43
diff changeset
   167
        "/ then interpret positional argument as PID and attach to it.
25d82943a3cf Allow VDB to be launched without PID or program to debug
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 43
diff changeset
   168
        "/ Otherwise, interpret positional arguments
25d82943a3cf Allow VDB to be launched without PID or program to debug
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 43
diff changeset
   169
        (programExecutable asFilename exists not and: [ programPid notNil and: [ programArgs isEmpty ]]) ifTrue:[
25d82943a3cf Allow VDB to be launched without PID or program to debug
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 43
diff changeset
   170
            attach := true.
25d82943a3cf Allow VDB to be launched without PID or program to debug
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 43
diff changeset
   171
        ] ifFalse:[
25d82943a3cf Allow VDB to be launched without PID or program to debug
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 43
diff changeset
   172
            programExecutable asFilename exists ifFalse:[
25d82943a3cf Allow VDB to be launched without PID or program to debug
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 43
diff changeset
   173
                self error: 'cannot find program executable: ', programExecutable.
25d82943a3cf Allow VDB to be launched without PID or program to debug
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 43
diff changeset
   174
            ].
43
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
   175
        ].
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
   176
    ].
47
25d82943a3cf Allow VDB to be launched without PID or program to debug
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 43
diff changeset
   177
43
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
   178
    Debugger := DebugView ? MiniDebugger.
47
25d82943a3cf Allow VDB to be launched without PID or program to debug
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 43
diff changeset
   179
    Inspector := InspectorView ? MiniInspector.
43
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
   180
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
   181
    debugger := GDBDebugger new.
47
25d82943a3cf Allow VDB to be launched without PID or program to debug
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 43
diff changeset
   182
    attach ifTrue:[
43
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
   183
        debugger attach: programPid
47
25d82943a3cf Allow VDB to be launched without PID or program to debug
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 43
diff changeset
   184
    ] ifFalse:[
25d82943a3cf Allow VDB to be launched without PID or program to debug
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 43
diff changeset
   185
        programExecutable notNil ifTrue:[
25d82943a3cf Allow VDB to be launched without PID or program to debug
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 43
diff changeset
   186
            debugger executable: programExecutable arguments: programArgs.
25d82943a3cf Allow VDB to be launched without PID or program to debug
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 43
diff changeset
   187
        ].
43
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
   188
    ].
18
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   189
    Smalltalk openDisplay.
43
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
   190
    VDBDebuggerApplication openFor: debugger.
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
   191
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
   192
    "
47
25d82943a3cf Allow VDB to be launched without PID or program to debug
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 43
diff changeset
   193
        VDBStartup main: #()
43
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
   194
        VDBStartup main: #('ls')
47
25d82943a3cf Allow VDB to be launched without PID or program to debug
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 43
diff changeset
   195
        VDBStartup main: #('/bin/ls' '/tmp')
43
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
   196
    "
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
   197
47
25d82943a3cf Allow VDB to be launched without PID or program to debug
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 43
diff changeset
   198
    "Modified: / 13-09-2017 / 12:54:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
18
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   199
!
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   200
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   201
usage
47
25d82943a3cf Allow VDB to be launched without PID or program to debug
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 43
diff changeset
   202
    Stdout nextPutAll:'usage: '; nextPutAll: self applicationName; nextPutAll: ' [OPTIONS] [PROGRAM [ARGS][ '; cr.
25d82943a3cf Allow VDB to be launched without PID or program to debug
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 43
diff changeset
   203
    Stdout nextPutAll:'       '; nextPutAll: self applicationName; nextPutAll: ' [OPTIONS] [PID]'; cr.
43
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
   204
                                                                          "|"
47
25d82943a3cf Allow VDB to be launched without PID or program to debug
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 43
diff changeset
   205
    Stdout nextPutLine:'
43
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
   206
options:
47
25d82943a3cf Allow VDB to be launched without PID or program to debug
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 43
diff changeset
   207
 --preference FILE ............ read user settings from FILE
25d82943a3cf Allow VDB to be launched without PID or program to debug
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 43
diff changeset
   208
 --no-preferences ............. do not read user settings at all
43
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
   209
 --help ....................... output this message
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
   210
'.
18
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   211
43
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
   212
    Smalltalk exitIfStandalone: 0.
c98aa29401f7 Initia support for running debugger as standalone application
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 37
diff changeset
   213
47
25d82943a3cf Allow VDB to be launched without PID or program to debug
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 43
diff changeset
   214
    "Modified: / 13-09-2017 / 22:12:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
18
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   215
! !
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   216
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   217
!VDBStartup class methodsFor:'documentation'!
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   218
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   219
version_HG
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   220
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   221
    ^ '$Changeset: <not expanded> $'
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   222
! !
0f44fe9848a0 Added standalone startup class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   223