Package: DbgpDebugger$3

DbgpDebugger$3

nameinstructionbranchcomplexitylinemethod
finish(IDbgpStatus, DbgpException)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
{...}
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * #%~
3: * org.overture.ide.debug
4: * %%
5: * Copyright (C) 2008 - 2014 Overture
6: * %%
7: * This program is free software: you can redistribute it and/or modify
8: * it under the terms of the GNU General Public License as
9: * published by the Free Software Foundation, either version 3 of the
10: * License, or (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public
18: * License along with this program. If not, see
19: * <http://www.gnu.org/licenses/gpl-3.0.html>.
20: * #~%
21: */
22: package org.overture.ide.debug.core.model.internal.operations;
23:
24: import org.overture.ide.debug.core.dbgp.IDbgpFeature;
25: import org.overture.ide.debug.core.dbgp.IDbgpSession;
26: import org.overture.ide.debug.core.dbgp.IDbgpStatus;
27: import org.overture.ide.debug.core.dbgp.commands.IDbgpCoreCommands;
28: import org.overture.ide.debug.core.dbgp.commands.IDbgpExtendedCommands;
29: import org.overture.ide.debug.core.dbgp.commands.IDbgpFeatureCommands;
30: import org.overture.ide.debug.core.dbgp.commands.IDbgpStreamCommands;
31: import org.overture.ide.debug.core.dbgp.exceptions.DbgpException;
32: import org.overture.ide.debug.core.model.IVdmThread;
33:
34: public class DbgpDebugger
35: {
36:         // Operations
37:         private final DbgpStepIntoOperation stepIntoOperation;
38:
39:         private final DbgpStepOverOperation stepOverOperation;
40:
41:         private final DbgpStepReturnOperation stepReturnOperation;
42:
43:         private DbgpSuspendOperation suspendOperation;
44:
45:         private final DbgpResumeOperation resumeOperation;
46:
47:         private final DbgpTerminateOperation terminateOperation;
48:
49:         private final IDbgpSession session;
50:
51:         public DbgpDebugger(IVdmThread thread, final IDbgpDebuggerFeedback end)
52:         {
53:
54:                 this.session = thread.getDbgpSession();
55:
56:                 /*
57:                  * FIXME should use single command queue here to guarantee we handle responses in the same sequences as we send
58:                  * requests
59:                  */
60:                 stepIntoOperation = new DbgpStepIntoOperation(thread, new DbgpOperation.IResultHandler()
61:                 {
62:                         public void finish(IDbgpStatus status, DbgpException e)
63:                         {
64:                                 end.endStepInto(e, status);
65:                         }
66:                 });
67:
68:                 stepOverOperation = new DbgpStepOverOperation(thread, new DbgpOperation.IResultHandler()
69:                 {
70:                         public void finish(IDbgpStatus status, DbgpException e)
71:                         {
72:                                 end.endStepOver(e, status);
73:                         }
74:                 });
75:
76:                 stepReturnOperation = new DbgpStepReturnOperation(thread, new DbgpOperation.IResultHandler()
77:                 {
78:                         public void finish(IDbgpStatus status, DbgpException e)
79:                         {
80:                                 end.endStepReturn(e, status);
81:                         }
82:                 });
83:
84:                 suspendOperation = new DbgpSuspendOperation(thread, new DbgpOperation.IResultHandler()
85:                 {
86:                         public void finish(IDbgpStatus status, DbgpException e)
87:                         {
88:                                 end.endSuspend(e, status);
89:                         }
90:                 });
91:
92:                 resumeOperation = new DbgpResumeOperation(thread, new DbgpOperation.IResultHandler()
93:                 {
94:                         public void finish(IDbgpStatus status, DbgpException e)
95:                         {
96:                                 end.endResume(e, status);
97:                         }
98:                 });
99:
100:                 terminateOperation = new DbgpTerminateOperation(thread, new DbgpOperation.IResultHandler()
101:                 {
102:                         public void finish(IDbgpStatus status, DbgpException e)
103:                         {
104:                                 end.endTerminate(e, status);
105:                         }
106:                 });
107:         }
108:
109:         public void stepInto()
110:         {
111:                 stepIntoOperation.schedule();
112:         }
113:
114:         public void stepOver()
115:         {
116:                 stepOverOperation.schedule();
117:         }
118:
119:         public void stepReturn()
120:         {
121:                 stepReturnOperation.schedule();
122:         }
123:
124:         public void suspend()
125:         {
126:                 suspendOperation.schedule();
127:         }
128:
129:         public void resume()
130:         {
131:                 resumeOperation.schedule();
132:         }
133:
134:         public void terminate()
135:         {
136:                 terminateOperation.schedule();
137:         }
138:
139:         // Feature helper methods
140:         public IDbgpFeature getFeature(String name) throws DbgpException
141:         {
142:                 IDbgpCoreCommands core = session.getCoreCommands();
143:                 return core.getFeature(name);
144:         }
145:
146:         public void setFeature(String name, String value) throws DbgpException
147:         {
148:                 IDbgpCoreCommands core = session.getCoreCommands();
149:                 core.setFeature(name, value);
150:         }
151:
152:         public boolean isFeatureSupported(String name) throws DbgpException
153:         {
154:                 return getFeature(name).isSupported();
155:         }
156:
157:         public boolean getFeatureBoolean(String name) throws DbgpException
158:         {
159:                 return getFeature(name).getValue().equals(IDbgpFeature.ONE_VALUE);
160:         }
161:
162:         public void setFeatureBoolean(String name, boolean value)
163:                         throws DbgpException
164:         {
165:                 setFeature(name, value ? IDbgpFeature.ONE_VALUE
166:                                 : IDbgpFeature.ZERO_VALUE);
167:         }
168:
169:         public int getFeatureInteger(String name) throws DbgpException
170:         {
171:                 return Integer.parseInt(getFeature(name).getValue());
172:         }
173:
174:         public void setFeatureInteger(String name, int value) throws DbgpException
175:         {
176:                 setFeature(name, Integer.toString(value));
177:         }
178:
179:         // Must available features
180:         public boolean isSupportsThreads() throws DbgpException
181:         {
182:                 return getFeature(IDbgpFeatureCommands.LANGUAGE_SUPPORTS_THREADS).getValue().equals(IDbgpFeature.ONE_VALUE);
183:         }
184:
185:         public String getLanguageName() throws DbgpException
186:         {
187:                 return getFeature(IDbgpFeatureCommands.LANGUAGE_NAME).getValue();
188:         }
189:
190:         public String getLanguageVersion() throws DbgpException
191:         {
192:                 return getFeature(IDbgpFeatureCommands.LANGUAGE_VERSION).getValue();
193:         }
194:
195:         public String getEncoding() throws DbgpException
196:         {
197:                 return getFeature(IDbgpFeatureCommands.ENCODING).getValue();
198:         }
199:
200:         public String getDataEncoding() throws DbgpException
201:         {
202:                 return getFeature(IDbgpFeatureCommands.DATA_ENCODING).getValue();
203:         }
204:
205:         public String getProtocolVersion() throws DbgpException
206:         {
207:                 return getFeature(IDbgpFeatureCommands.PROTOCOL_VERSION).getValue();
208:         }
209:
210:         public boolean isSupportsAsync() throws DbgpException
211:         {
212:                 return getFeature(IDbgpFeatureCommands.SUPPORTS_ASYNC).getValue().equals(IDbgpFeature.ONE_VALUE);
213:         }
214:
215:         public String getBreakpointLanguages() throws DbgpException
216:         {
217:                 return getFeature(IDbgpFeatureCommands.BREAKPOINT_LANGUAGES).getValue();
218:         }
219:
220:         public String getBreakpointTypes() throws DbgpException
221:         {
222:                 return getFeature(IDbgpFeatureCommands.BREAKPOINT_TYPES).getValue();
223:         }
224:
225:         // Multiple sessions
226:         public boolean getMultipleSessions() throws DbgpException
227:         {
228:                 return getFeature(IDbgpFeatureCommands.MULTIPLE_SESSIONS).getValue().equals(IDbgpFeature.ONE_VALUE);
229:         }
230:
231:         public void setMultipleSessions(boolean value) throws DbgpException
232:         {
233:                 setFeature(IDbgpFeatureCommands.MULTIPLE_SESSIONS, value ? IDbgpFeature.ONE_VALUE
234:                                 : IDbgpFeature.ZERO_VALUE);
235:         }
236:
237:         // Max children
238:         public int getMaxChildren() throws DbgpException
239:         {
240:                 return getFeatureInteger(IDbgpFeatureCommands.MAX_CHILDREN);
241:         }
242:
243:         public void setMaxChildren(int value) throws DbgpException
244:         {
245:                 setFeatureInteger(IDbgpFeatureCommands.MAX_CHILDREN, value);
246:         }
247:
248:         // Max data
249:         public int getMaxData() throws DbgpException
250:         {
251:                 return getFeatureInteger(IDbgpFeatureCommands.MAX_DATA);
252:         }
253:
254:         public void setMaxData(int value) throws DbgpException
255:         {
256:                 setFeatureInteger(IDbgpFeatureCommands.MAX_DATA, value);
257:         }
258:
259:         // Max depth
260:         public int getMaxDepth() throws DbgpException
261:         {
262:                 return getFeatureInteger(IDbgpFeatureCommands.MAX_DEPTH);
263:         }
264:
265:         public void setMaxDepth(int value) throws DbgpException
266:         {
267:                 setFeatureInteger(IDbgpFeatureCommands.MAX_DEPTH, value);
268:         }
269:
270:         // Optional features
271:
272:         // Post morten
273:         public boolean isPostMortenSupported() throws DbgpException
274:         {
275:                 return isFeatureSupported(IDbgpFeatureCommands.SUPPORTS_POSTMORTEN);
276:         }
277:
278:         public boolean getPostMorten() throws DbgpException
279:         {
280:                 return getFeatureBoolean(IDbgpFeatureCommands.SUPPORTS_POSTMORTEN);
281:         }
282:
283:         // Show hidden
284:         public boolean isShowHiddenSupported() throws DbgpException
285:         {
286:                 return isFeatureSupported(IDbgpFeatureCommands.SHOW_HIDDEN);
287:         }
288:
289:         public boolean getShowHidden() throws DbgpException
290:         {
291:                 return getFeatureBoolean(IDbgpFeatureCommands.SHOW_HIDDEN);
292:         }
293:
294:         public void setShowHidden(boolean value) throws DbgpException
295:         {
296:                 setFeatureBoolean(IDbgpFeatureCommands.SHOW_HIDDEN, value);
297:         }
298:
299:         // Notfy ok
300:         public boolean isNotifyOkSupported() throws DbgpException
301:         {
302:                 return isFeatureSupported(IDbgpFeatureCommands.NOTIFY_OK);
303:         }
304:
305:         public boolean getNotifyOk() throws DbgpException
306:         {
307:                 return getFeatureBoolean(IDbgpFeatureCommands.NOTIFY_OK);
308:         }
309:
310:         public void setNotifyOk(boolean value) throws DbgpException
311:         {
312:                 setFeatureBoolean(IDbgpFeatureCommands.NOTIFY_OK, value);
313:         }
314:
315:         protected void configureStdout(int value) throws DbgpException
316:         {
317:                 IDbgpCoreCommands core = session.getCoreCommands();
318:                 // TODO: error handling
319:                 core.configureStdout(value);
320:         }
321:
322:         // Stdout
323:         public void disableStdout() throws DbgpException
324:         {
325:                 configureStdout(IDbgpStreamCommands.DISABLE);
326:         }
327:
328:         public void copyStdout() throws DbgpException
329:         {
330:                 configureStdout(IDbgpStreamCommands.COPY);
331:         }
332:
333:         public void redirectStdout() throws DbgpException
334:         {
335:                 configureStdout(IDbgpStreamCommands.REDIRECT);
336:         }
337:
338:         // Stderr
339:         protected void configureStderr(int value) throws DbgpException
340:         {
341:                 IDbgpCoreCommands core = session.getCoreCommands();
342:                 // TODO: error handling
343:                 core.configureStderr(value);
344:         }
345:
346:         public void disableStderr() throws DbgpException
347:         {
348:                 configureStderr(IDbgpStreamCommands.DISABLE);
349:         }
350:
351:         public void copyStderr() throws DbgpException
352:         {
353:                 configureStderr(IDbgpStreamCommands.COPY);
354:         }
355:
356:         public void redirectStderr() throws DbgpException
357:         {
358:                 configureStderr(IDbgpStreamCommands.REDIRECT);
359:         }
360:
361:         // Stdin
362:         protected void configureStdin(int value) throws DbgpException
363:         {
364:                 IDbgpExtendedCommands extended = session.getExtendedCommands();
365:                 // TODO: handling
366:                 extended.configureStdin(value);
367:         }
368:
369:         public void disableStdin() throws DbgpException
370:         {
371:                 configureStdin(IDbgpExtendedCommands.DISABLE);
372:         }
373:
374:         public void redirectStdin() throws DbgpException
375:         {
376:                 configureStdin(IDbgpExtendedCommands.REDIRECT);
377:         }
378:
379:         public static void printEngineInfo(DbgpDebugger d) throws DbgpException
380:         {
381:                 // TODO: to debug log
382:                 System.out.println(IDbgpFeatureCommands.LANGUAGE_SUPPORTS_THREADS
383:                                 + ": " + d.isSupportsThreads()); //$NON-NLS-1$
384:                 System.out.println(IDbgpFeatureCommands.LANGUAGE_NAME + ": " //$NON-NLS-1$
385:                                 + d.getLanguageName());
386:                 System.out.println(IDbgpFeatureCommands.LANGUAGE_VERSION + ": " //$NON-NLS-1$
387:                                 + d.getLanguageVersion());
388:                 System.out.println(IDbgpFeatureCommands.ENCODING + ": " //$NON-NLS-1$
389:                                 + d.getEncoding());
390:                 System.out.println(IDbgpFeatureCommands.DATA_ENCODING + ": " //$NON-NLS-1$
391:                                 + d.getDataEncoding());
392:                 System.out.println(IDbgpFeatureCommands.PROTOCOL_VERSION + ": " //$NON-NLS-1$
393:                                 + d.getProtocolVersion());
394:                 System.out.println(IDbgpFeatureCommands.SUPPORTS_ASYNC + ": " //$NON-NLS-1$
395:                                 + d.isSupportsAsync());
396:                 System.out.println(IDbgpFeatureCommands.BREAKPOINT_LANGUAGES + ": " //$NON-NLS-1$
397:                                 + d.getBreakpointLanguages());
398:                 System.out.println(IDbgpFeatureCommands.BREAKPOINT_TYPES + ": " //$NON-NLS-1$
399:                                 + d.getBreakpointTypes());
400:                 System.out.println(IDbgpFeatureCommands.MULTIPLE_SESSIONS + ": " //$NON-NLS-1$
401:                                 + d.getMultipleSessions());
402:                 System.out.println(IDbgpFeatureCommands.MAX_CHILDREN + ": " //$NON-NLS-1$
403:                                 + d.getMaxChildren());
404:                 System.out.println(IDbgpFeatureCommands.MAX_DATA + ": " //$NON-NLS-1$
405:                                 + d.getMaxData());
406:                 System.out.println(IDbgpFeatureCommands.MAX_DEPTH + ": " //$NON-NLS-1$
407:                                 + d.getMaxDepth());
408:
409:                 if (d.isPostMortenSupported())
410:                 {
411:                         System.out.println("Support of " //$NON-NLS-1$
412:                                         + IDbgpFeatureCommands.SUPPORTS_POSTMORTEN
413:                                         + ": true, value: " + d.getPostMorten()); //$NON-NLS-1$
414:                 } else
415:                 {
416:                         System.out.println("Support of " //$NON-NLS-1$
417:                                         + IDbgpFeatureCommands.SUPPORTS_POSTMORTEN + ": false"); //$NON-NLS-1$
418:                 }
419:
420:                 if (d.isShowHiddenSupported())
421:                 {
422:                         System.out.println("Support of " + IDbgpFeatureCommands.SHOW_HIDDEN //$NON-NLS-1$
423:                                         + ": true, value: " + d.getShowHidden()); //$NON-NLS-1$
424:                 } else
425:                 {
426:                         System.out.println("Support of " + IDbgpFeatureCommands.SHOW_HIDDEN //$NON-NLS-1$
427:                                         + ": false"); //$NON-NLS-1$
428:                 }
429:
430:                 if (d.isNotifyOkSupported())
431:                 {
432:                         System.out.println("Support of " + IDbgpFeatureCommands.NOTIFY_OK //$NON-NLS-1$
433:                                         + ": true, value: " + d.getNotifyOk()); //$NON-NLS-1$
434:                 } else
435:                 {
436:                         System.out.println("Support of " + IDbgpFeatureCommands.NOTIFY_OK //$NON-NLS-1$
437:                                         + ": false"); //$NON-NLS-1$
438:                 }
439:         }
440:
441:         public IDbgpSession getSession()
442:         {
443:                 return this.session;
444:         }
445: }