GDBProcess.st
changeset 93 b1715ebf8df1
parent 91 472a4841a8b6
child 95 f417138e9c48
equal deleted inserted replaced
92:0f11fece852c 93:b1715ebf8df1
    19 "{ Package: 'jv:libgdbs' }"
    19 "{ Package: 'jv:libgdbs' }"
    20 
    20 
    21 "{ NameSpace: Smalltalk }"
    21 "{ NameSpace: Smalltalk }"
    22 
    22 
    23 Object subclass:#GDBProcess
    23 Object subclass:#GDBProcess
    24 	instanceVariableNames:'pid connection'
    24 	instanceVariableNames:'pid connection debuggerInput debuggerOutput'
    25 	classVariableNames:''
    25 	classVariableNames:'GDBExecutable'
    26 	poolDictionaries:''
    26 	poolDictionaries:''
    27 	category:'GDB-Private'
    27 	category:'GDB-Private'
    28 !
    28 !
    29 
    29 
    30 !GDBProcess class methodsFor:'documentation'!
    30 !GDBProcess class methodsFor:'documentation'!
    51 ! !
    51 ! !
    52 
    52 
    53 !GDBProcess class methodsFor:'instance creation'!
    53 !GDBProcess class methodsFor:'instance creation'!
    54 
    54 
    55 new
    55 new
    56     "return an initialized instance"
    56     | class |
    57 
    57 
    58     ^ self basicNew initialize.
    58     class := OperatingSystem isUNIXlike"false" ifTrue:[ GDBUnixProcess ] ifFalse: [ self ].
       
    59     ^ class basicNew initialize.
       
    60 
       
    61     "Modified: / 16-12-2017 / 00:10:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    62 ! !
       
    63 
       
    64 !GDBProcess class methodsFor:'accessing'!
       
    65 
       
    66 gdbExecutable
       
    67     ^ GDBExecutable
       
    68 
       
    69     "Created: / 01-03-2015 / 08:07:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    70 !
       
    71 
       
    72 gdbExecutable: aString
       
    73     GDBExecutable := aString
       
    74 
       
    75     "Created: / 01-03-2015 / 08:07:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    59 ! !
    76 ! !
    60 
    77 
    61 !GDBProcess class methodsFor:'queries'!
    78 !GDBProcess class methodsFor:'queries'!
    62 
    79 
    63 isAbstract
    80 isAbstract
    73 connection:aGDBConnection
    90 connection:aGDBConnection
    74     connection := aGDBConnection.
    91     connection := aGDBConnection.
    75 !
    92 !
    76 
    93 
    77 consoleInput
    94 consoleInput
    78     ^ self subclassResponsibility
    95     ^ nil
    79 
    96 
    80     "Created: / 02-06-2017 / 23:35:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    97     "Created: / 02-06-2017 / 23:35:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    98     "Modified: / 15-12-2017 / 23:58:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    81 !
    99 !
    82 
   100 
    83 consoleOutput
   101 consoleOutput
    84     ^ self subclassResponsibility
   102     ^ nil
    85 
   103 
    86     "Created: / 02-06-2017 / 23:35:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   104     "Created: / 02-06-2017 / 23:35:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   105     "Modified: / 15-12-2017 / 23:58:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    87 !
   106 !
    88 
   107 
    89 debuggerInput
   108 debuggerInput
    90     "raise an error: must be redefined in concrete subclass(es)"
   109     "raise an error: must be redefined in concrete subclass(es)"
    91 
   110 
    92     ^ self subclassResponsibility
   111     ^ debuggerInput
       
   112 
       
   113     "Modified: / 15-12-2017 / 23:58:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    93 !
   114 !
    94 
   115 
    95 debuggerOutput
   116 debuggerOutput
    96     "raise an error: must be redefined in concrete subclass(es)"
   117     "raise an error: must be redefined in concrete subclass(es)"
    97 
   118 
    98     ^ self subclassResponsibility
   119     ^ debuggerOutput
       
   120 
       
   121     "Modified: / 15-12-2017 / 23:58:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    99 !
   122 !
   100 
   123 
   101 pid
   124 pid
   102     ^ pid
   125     ^ pid
   103 ! !
   126 ! !
   104 
   127 
   105 !GDBProcess methodsFor:'initialization & release'!
   128 !GDBProcess methodsFor:'initialization & release'!
   106 
   129 
       
   130 initialize
       
   131     | inputPipe  input  outputPipe  output  args |
       
   132 
       
   133     inputPipe := NonPositionableExternalStream makePipe.
       
   134     input := inputPipe second.
       
   135     outputPipe := NonPositionableExternalStream makePipe.
       
   136     output := outputPipe first.
       
   137     args := (Array new:5)
       
   138              at: 1 put: GDBExecutable ? '/usr/bin/gdb';
       
   139              at: 2 put: '-q';
       
   140              at: 3 put: '-nx';
       
   141              at: 4 put: '--interpreter';
       
   142              at: 5 put: 'mi2';
       
   143              yourself.
       
   144 
       
   145     Processor 
       
   146         monitor:[
       
   147             pid := OperatingSystem 
       
   148                     exec:args first
       
   149                     withArguments:args
       
   150                     environment:OperatingSystem getEnvironment
       
   151                     fileDescriptors: (Array
       
   152                             with: inputPipe first fileDescriptor
       
   153                             with: outputPipe second fileDescriptor
       
   154                             with: outputPipe second fileDescriptor
       
   155                         )
       
   156                     fork:true
       
   157                     newPgrp:false
       
   158                     inDirectory:Filename currentDirectory
       
   159                     showWindow: false.      
       
   160             debuggerInput := input.
       
   161             debuggerOutput := output.
       
   162             pid.
       
   163         ]
       
   164         action:[:stat | self exited:stat. ].
       
   165     inputPipe first close.
       
   166     outputPipe second close.
       
   167     pid isNil ifTrue:[
       
   168         input close.
       
   169         output close.
       
   170         self error:'Failed to launch gdb'.
       
   171     ].
       
   172 
       
   173     "Created: / 12-12-2017 / 21:04:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   174 !
       
   175 
   107 release
   176 release
   108     pid := connection := nil.
   177     pid := connection := nil.
       
   178     debuggerInput notNil ifTrue:[ debuggerInput close ].
       
   179     debuggerOutput notNil ifTrue:[ debuggerOutput close ].
   109 
   180 
   110     "Created: / 20-06-2014 / 21:35:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   181     "Created: / 20-06-2014 / 21:35:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   111     "Modified: / 02-06-2017 / 23:33:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   182     "Modified: / 15-12-2017 / 23:59:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   112 ! !
   183 ! !
   113 
   184 
   114 !GDBProcess methodsFor:'private'!
   185 !GDBProcess methodsFor:'private'!
   115 
   186 
   116 exited: status
   187 exited: status