[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
AW: [cdt-debug-dev] getting current debug session
|
Hi,
I did this a while ago for a custom made view to see the content of the
mailboxes on my target system. I started with a new plug-in which
implemented a view (this is something that the new project wizard can
generate for you out of the box). Then I took the following steps:
Step 1) Register for debug events when the view was created:
org.eclipse.debug.core.DebugPlugin.getDefault().addDebugEventListener(ha
ndler);
where handler is a class you implement yourself.
Step 2) Evaluate debug events in your handler class
public void handleDebugEvents(DebugEvent[] events) {
for (int i = 0; i < events.length; i++) {
DebugEvent event = events[i];
Object eventSource = event.getSource();
if (eventSource instanceof CDebugTarget) {
CDebugTarget debugTarget =
(CDebugTarget) eventSource;
handleCDebugTarget(debugTarget);
if (event.getKind()==event.SUSPEND) {
handleCDebugTargetSuspend();
}
}
}
}
If the event comes from a CDebugTarget then it is from a CDT debug
session. The above snippet contains two further function calls:
handleCDebugTarget() and handleCDebugTargetSuspend():
Step 3) Get the debug session from the CDebugTarget:
private CDebugTarget target ;
private MISession session ;
private void handleCDebugTarget(CDebugTarget debugTarget) {
target = debugTarget ;
ICDISession cdiSession =
debugTarget.getCDISession();
ICDITarget[] targets = cdiSession.getTargets();
ICDITarget cdiTarget = null ;
for (int i = 0; i < targets.length; i++) {
ICDITarget cdiTargetCandidate =
targets[i];
if (cdiTargetCandidate instanceof
Target) {
cdiTarget = cdiTargetCandidate ;
break ;
}
}
if (cdiTarget!=null) {
Target miTarget = (Target) cdiTarget;
session = miTarget.getMISession();
observer = new MISessionObserver();
session.addObserver(observer);
}
}
}
Step 4) Send some commands to the session when the session suspends e.g.
to refresh your view (here it is the info signals command):
private void handleCDebugTargetSuspend() {
if ((target != null) && (session != null)) {
final CLIInfoSignals c =
session.getCommandFactory().createCLIInfoSignals();
try {
session.postCommand(c);
CLIInfoSignalsInfo info =
c.getMIInfoSignalsInfo();
MISigHandle handles[] =
info.getMISignals();
// and now do something with the results
here ...
} catch (MIException e) {
EcosmboxviewPlugin.say(e);
}
session.toString();
}
}
If this works for you you owe me something :-) It was a bit of work to
find this out when I did it.
Hope this helps, anyway.
Norbert