1 "{ Package: 'jv:libgdbs' }" |
|
2 |
|
3 Object subclass:#GDB |
|
4 instanceVariableNames:'driver commandSequenceNumber inferiorStateSequenceNumber' |
|
5 classVariableNames:'' |
|
6 poolDictionaries:'GDBCommandStatus' |
|
7 category:'GDB-Core' |
|
8 ! |
|
9 |
|
10 |
|
11 !GDB class methodsFor:'instance creation'! |
|
12 |
|
13 new |
|
14 "return an initialized instance" |
|
15 |
|
16 ^ self basicNew initialize. |
|
17 ! ! |
|
18 |
|
19 !GDB methodsFor:'accessing'! |
|
20 |
|
21 announcer |
|
22 ^ driver eventAnnouncer. |
|
23 |
|
24 "Created: / 02-06-2014 / 23:06:20 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
25 ! |
|
26 |
|
27 inferiorStderr |
|
28 ^ driver inferiorPTY master |
|
29 |
|
30 "Created: / 09-06-2014 / 10:01:21 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
31 "Modified: / 09-06-2014 / 18:26:55 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
32 ! |
|
33 |
|
34 inferiorStdin |
|
35 ^ driver inferiorPTY master |
|
36 |
|
37 "Created: / 09-06-2014 / 10:00:30 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
38 "Modified: / 09-06-2014 / 18:27:03 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
39 ! |
|
40 |
|
41 inferiorStdout |
|
42 ^ driver inferiorPTY master |
|
43 |
|
44 "Created: / 09-06-2014 / 10:01:16 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
45 "Modified: / 09-06-2014 / 18:27:11 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
46 ! ! |
|
47 |
|
48 !GDB methodsFor:'accessing-private'! |
|
49 |
|
50 currentInferiorStateSequnceNumber |
|
51 ^ inferiorStateSequenceNumber |
|
52 |
|
53 "Created: / 19-06-2014 / 22:22:08 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
54 ! |
|
55 |
|
56 nextCommandSequnceNumber |
|
57 commandSequenceNumber := commandSequenceNumber + 1. |
|
58 commandSequenceNumber == SmallInteger maxVal ifTrue:[ |
|
59 commandSequenceNumber := 0. |
|
60 ]. |
|
61 ^ commandSequenceNumber |
|
62 |
|
63 "Created: / 02-06-2014 / 23:48:19 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
64 ! |
|
65 |
|
66 nextInferiorStateSequnceNumber |
|
67 inferiorStateSequenceNumber := inferiorStateSequenceNumber + 1. |
|
68 inferiorStateSequenceNumber == SmallInteger maxVal ifTrue:[ |
|
69 inferiorStateSequenceNumber := 0. |
|
70 ]. |
|
71 ^ inferiorStateSequenceNumber |
|
72 |
|
73 "Created: / 02-06-2014 / 23:48:38 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
74 ! ! |
|
75 |
|
76 !GDB methodsFor:'commands'! |
|
77 |
|
78 send: aGDBCommand |
|
79 ^ self send: aGDBCommand wait: true. |
|
80 |
|
81 "Created: / 03-06-2014 / 00:10:38 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
82 ! |
|
83 |
|
84 send: aGDBCommand wait: aBoolean |
|
85 "Sends given command to GDB. If `aBoolean` is true, wait for |
|
86 command to finish. Otherwise, return immediately." |
|
87 |
|
88 | token blocker releaser | |
|
89 |
|
90 token := self nextCommandSequnceNumber. |
|
91 aGDBCommand token: token. |
|
92 aBoolean ifTrue:[ |
|
93 releaser := [ :ev | |
|
94 ev token == token ifTrue:[ |
|
95 self announcer unsubscribe: releaser. |
|
96 blocker signal. |
|
97 ]]. |
|
98 blocker := Semaphore new. |
|
99 self announcer when: GDBCommandResultEvent do: releaser. |
|
100 driver pushEvent: (GDBCommandEvent new command: aGDBCommand). |
|
101 blocker wait. |
|
102 ] ifFalse:[ |
|
103 driver pushEvent: (GDBCommandEvent new command: aGDBCommand). |
|
104 ] |
|
105 |
|
106 "Created: / 02-06-2014 / 23:45:43 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
107 "Modified: / 04-06-2014 / 09:32:20 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
108 ! ! |
|
109 |
|
110 !GDB methodsFor:'event handling'! |
|
111 |
|
112 onCommandResult: aGDBCommandResultEvent |
|
113 aGDBCommandResultEvent result status == CommandStatusExit ifTrue:[ |
|
114 driver pushEvent: GDBExitEvent new. |
|
115 ]. |
|
116 |
|
117 "Created: / 02-06-2014 / 23:40:18 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
118 "Modified: / 04-06-2014 / 09:30:40 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
119 ! |
|
120 |
|
121 onExecutionEvent: aGDBExecutionEvent |
|
122 self nextInferiorStateSequnceNumber. |
|
123 |
|
124 "Created: / 19-06-2014 / 22:21:47 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
125 ! |
|
126 |
|
127 onExit: aGDBExitEvent |
|
128 self release. |
|
129 |
|
130 "Created: / 03-06-2014 / 00:36:00 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
131 "Modified: / 04-06-2014 / 09:28:59 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
132 ! ! |
|
133 |
|
134 !GDB methodsFor:'finalization'! |
|
135 |
|
136 finalize |
|
137 self release. |
|
138 |
|
139 "Created: / 26-05-2014 / 21:23:28 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
140 ! ! |
|
141 |
|
142 !GDB methodsFor:'initialize & release'! |
|
143 |
|
144 initialize |
|
145 self registerForFinalization. |
|
146 driver := GDBLauncher startGDB. |
|
147 |
|
148 commandSequenceNumber := 0. |
|
149 inferiorStateSequenceNumber := 0. |
|
150 |
|
151 driver eventAnnouncerInternal |
|
152 when: GDBCommandResultEvent send: #onCommandResult: to: self; |
|
153 when: GDBExitEvent send: #onExit: to: self; |
|
154 when: GDBExecutionEvent send: #onExecutionEvent: to: self. |
|
155 |
|
156 |
|
157 driver eventPumpStart. |
|
158 driver eventDispatchStart. |
|
159 |
|
160 "/ self send: (GDBMICommand inferiorTtySet: driver inferiorPTY name). |
|
161 self send: (GDBMI_inferior_tty_set arguments: { driver inferiorPTY name }) |
|
162 |
|
163 "Created: / 26-05-2014 / 21:23:04 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
164 "Modified: / 19-06-2014 / 22:22:57 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
165 ! |
|
166 |
|
167 release |
|
168 driver notNil ifTrue:[ |
|
169 driver release. |
|
170 driver := nil. |
|
171 ]. |
|
172 |
|
173 "Created: / 26-05-2014 / 21:24:04 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
174 ! ! |
|
175 |
|
176 !GDB class methodsFor:'documentation'! |
|
177 |
|
178 version_HG |
|
179 |
|
180 ^ '$Changeset: <not expanded> $' |
|
181 ! ! |
|
182 |
|