mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-06 09:16:02 +02:00
Deal with Shared Lib Events from GDB
This commit is contained in:
parent
551a927cf2
commit
081b8cd7ca
2 changed files with 59 additions and 25 deletions
|
@ -26,6 +26,7 @@ import org.eclipse.cdt.debug.mi.core.event.MIInferiorExitEvent;
|
||||||
import org.eclipse.cdt.debug.mi.core.event.MIInferiorSignalExitEvent;
|
import org.eclipse.cdt.debug.mi.core.event.MIInferiorSignalExitEvent;
|
||||||
import org.eclipse.cdt.debug.mi.core.event.MILocationReachedEvent;
|
import org.eclipse.cdt.debug.mi.core.event.MILocationReachedEvent;
|
||||||
import org.eclipse.cdt.debug.mi.core.event.MIRunningEvent;
|
import org.eclipse.cdt.debug.mi.core.event.MIRunningEvent;
|
||||||
|
import org.eclipse.cdt.debug.mi.core.event.MISharedLibEvent;
|
||||||
import org.eclipse.cdt.debug.mi.core.event.MISignalEvent;
|
import org.eclipse.cdt.debug.mi.core.event.MISignalEvent;
|
||||||
import org.eclipse.cdt.debug.mi.core.event.MISteppingRangeEvent;
|
import org.eclipse.cdt.debug.mi.core.event.MISteppingRangeEvent;
|
||||||
import org.eclipse.cdt.debug.mi.core.event.MIStoppedEvent;
|
import org.eclipse.cdt.debug.mi.core.event.MIStoppedEvent;
|
||||||
|
@ -64,9 +65,8 @@ public class RxThread extends Thread {
|
||||||
* Get the response, parse the output, dispatch for OOB
|
* Get the response, parse the output, dispatch for OOB
|
||||||
* search for the corresponding token in rxQueue for the ResultRecord.
|
* search for the corresponding token in rxQueue for the ResultRecord.
|
||||||
*/
|
*/
|
||||||
public void run () {
|
public void run() {
|
||||||
BufferedReader reader =
|
BufferedReader reader = new BufferedReader(new InputStreamReader(session.getChannelInputStream()));
|
||||||
new BufferedReader(new InputStreamReader(session.getChannelInputStream()));
|
|
||||||
try {
|
try {
|
||||||
String line;
|
String line;
|
||||||
while ((line = reader.readLine()) != null) {
|
while ((line = reader.readLine()) != null) {
|
||||||
|
@ -84,8 +84,8 @@ public class RxThread extends Thread {
|
||||||
if (session.getChannelInputStream() != null) {
|
if (session.getChannelInputStream() != null) {
|
||||||
Runnable cleanup = new Runnable() {
|
Runnable cleanup = new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
// Change the state of the inferior.
|
// Change the state of the inferior.
|
||||||
session.getMIInferior().setTerminated();
|
session.getMIInferior().setTerminated();
|
||||||
session.terminate();
|
session.terminate();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -125,10 +125,9 @@ public class RxThread extends Thread {
|
||||||
|
|
||||||
// Clear the accumulate oobList on each new Result Command
|
// Clear the accumulate oobList on each new Result Command
|
||||||
// response.
|
// response.
|
||||||
MIOOBRecord [] oobRecords =
|
MIOOBRecord[] oobRecords = (MIOOBRecord[]) oobList.toArray(new MIOOBRecord[0]);
|
||||||
(MIOOBRecord[])oobList.toArray(new MIOOBRecord[0]);
|
|
||||||
oobList.clear();
|
oobList.clear();
|
||||||
|
|
||||||
// Check if the state changed.
|
// Check if the state changed.
|
||||||
String state = rr.getResultClass();
|
String state = rr.getResultClass();
|
||||||
if ("running".equals(state)) {
|
if ("running".equals(state)) {
|
||||||
|
@ -174,7 +173,7 @@ public class RxThread extends Thread {
|
||||||
cmd.setMIOutput(response);
|
cmd.setMIOutput(response);
|
||||||
cmd.notifyAll();
|
cmd.notifyAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Some result record contains informaton specific to oob.
|
// Some result record contains informaton specific to oob.
|
||||||
// This will happen when CLI-Command is use, for example
|
// This will happen when CLI-Command is use, for example
|
||||||
// doing "run" will block and return a breakpointhit
|
// doing "run" will block and return a breakpointhit
|
||||||
|
@ -189,7 +188,7 @@ public class RxThread extends Thread {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MIEvent[] events = (MIEvent[])list.toArray(new MIEvent[list.size()]);
|
MIEvent[] events = (MIEvent[]) list.toArray(new MIEvent[list.size()]);
|
||||||
session.fireEvents(events);
|
session.fireEvents(events);
|
||||||
} // if response != null
|
} // if response != null
|
||||||
}
|
}
|
||||||
|
@ -199,15 +198,15 @@ public class RxThread extends Thread {
|
||||||
*/
|
*/
|
||||||
void processMIOOBRecord(MIOOBRecord oob, List list) {
|
void processMIOOBRecord(MIOOBRecord oob, List list) {
|
||||||
if (oob instanceof MIAsyncRecord) {
|
if (oob instanceof MIAsyncRecord) {
|
||||||
processMIOOBRecord((MIAsyncRecord)oob, list);
|
processMIOOBRecord((MIAsyncRecord) oob, list);
|
||||||
} else if (oob instanceof MIStreamRecord) {
|
} else if (oob instanceof MIStreamRecord) {
|
||||||
processMIOOBRecord((MIStreamRecord)oob);
|
processMIOOBRecord((MIStreamRecord) oob);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void processMIOOBRecord(MIAsyncRecord async, List list) {
|
void processMIOOBRecord(MIAsyncRecord async, List list) {
|
||||||
if (async instanceof MIExecAsyncOutput) {
|
if (async instanceof MIExecAsyncOutput) {
|
||||||
MIExecAsyncOutput exec = (MIExecAsyncOutput)async;
|
MIExecAsyncOutput exec = (MIExecAsyncOutput) async;
|
||||||
// Change of state.
|
// Change of state.
|
||||||
String state = exec.getAsyncClass();
|
String state = exec.getAsyncClass();
|
||||||
if ("stopped".equals(state)) {
|
if ("stopped".equals(state)) {
|
||||||
|
@ -218,7 +217,7 @@ public class RxThread extends Thread {
|
||||||
MIValue val = results[i].getMIValue();
|
MIValue val = results[i].getMIValue();
|
||||||
if (var.equals("reason")) {
|
if (var.equals("reason")) {
|
||||||
if (val instanceof MIConst) {
|
if (val instanceof MIConst) {
|
||||||
String reason =((MIConst)val).getString();
|
String reason = ((MIConst) val).getString();
|
||||||
e = createEvent(reason, exec);
|
e = createEvent(reason, exec);
|
||||||
if (e != null) {
|
if (e != null) {
|
||||||
list.add(e);
|
list.add(e);
|
||||||
|
@ -226,7 +225,24 @@ public class RxThread extends Thread {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GDB does not have reason when stopping on shared, hopefully
|
||||||
|
// this will be fix in newer version meanwhile, we will use a hack
|
||||||
|
// to cope. On most platform we can detect by looking at the
|
||||||
|
// console stream for phrase:
|
||||||
|
// ~"Stopped due to shared library event\n"
|
||||||
|
//
|
||||||
|
// Althought it is a _real_ bad idea to do this, we do not have
|
||||||
|
// any other alternatives.
|
||||||
|
String[] logs = getStreamRecords();
|
||||||
|
for (int i = 0; i < logs.length; i++) {
|
||||||
|
if (logs[i].equalsIgnoreCase("Stopped due to shared library event")) {
|
||||||
|
session.getMIInferior().setSuspended();
|
||||||
|
e = new MISharedLibEvent(exec);
|
||||||
|
list.add(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// We were stopped for some unknown reason, for example
|
// We were stopped for some unknown reason, for example
|
||||||
// GDB for temporary breakpoints will not send the
|
// GDB for temporary breakpoints will not send the
|
||||||
// "reason" ??? still fire a stopped event.
|
// "reason" ??? still fire a stopped event.
|
||||||
|
@ -247,7 +263,7 @@ public class RxThread extends Thread {
|
||||||
if (stream instanceof MIConsoleStreamOutput) {
|
if (stream instanceof MIConsoleStreamOutput) {
|
||||||
OutputStream console = session.getConsolePipe();
|
OutputStream console = session.getConsolePipe();
|
||||||
if (console != null) {
|
if (console != null) {
|
||||||
MIConsoleStreamOutput out = (MIConsoleStreamOutput)stream;
|
MIConsoleStreamOutput out = (MIConsoleStreamOutput) stream;
|
||||||
String str = out.getString();
|
String str = out.getString();
|
||||||
if (str != null) {
|
if (str != null) {
|
||||||
try {
|
try {
|
||||||
|
@ -263,7 +279,7 @@ public class RxThread extends Thread {
|
||||||
} else if (stream instanceof MITargetStreamOutput) {
|
} else if (stream instanceof MITargetStreamOutput) {
|
||||||
OutputStream target = session.getMIInferior().getPipedOutputStream();
|
OutputStream target = session.getMIInferior().getPipedOutputStream();
|
||||||
if (target != null) {
|
if (target != null) {
|
||||||
MITargetStreamOutput out = (MITargetStreamOutput)stream;
|
MITargetStreamOutput out = (MITargetStreamOutput) stream;
|
||||||
String str = out.getString();
|
String str = out.getString();
|
||||||
if (str != null) {
|
if (str != null) {
|
||||||
try {
|
try {
|
||||||
|
@ -277,7 +293,7 @@ public class RxThread extends Thread {
|
||||||
// This is meant for the gdb console.
|
// This is meant for the gdb console.
|
||||||
OutputStream log = session.getLogPipe();
|
OutputStream log = session.getLogPipe();
|
||||||
if (log != null) {
|
if (log != null) {
|
||||||
MILogStreamOutput out = (MILogStreamOutput)stream;
|
MILogStreamOutput out = (MILogStreamOutput) stream;
|
||||||
String str = out.getString();
|
String str = out.getString();
|
||||||
if (str != null) {
|
if (str != null) {
|
||||||
try {
|
try {
|
||||||
|
@ -297,13 +313,13 @@ public class RxThread extends Thread {
|
||||||
* Dispatch a thread to deal with the listeners.
|
* Dispatch a thread to deal with the listeners.
|
||||||
*/
|
*/
|
||||||
void processMIOOBRecord(MIResultRecord rr, List list) {
|
void processMIOOBRecord(MIResultRecord rr, List list) {
|
||||||
MIResult[] results = rr.getMIResults();
|
MIResult[] results = rr.getMIResults();
|
||||||
for (int i = 0; i < results.length; i++) {
|
for (int i = 0; i < results.length; i++) {
|
||||||
String var = results[i].getVariable();
|
String var = results[i].getVariable();
|
||||||
if (var.equals("reason")) {
|
if (var.equals("reason")) {
|
||||||
MIValue value = results[i].getMIValue();
|
MIValue value = results[i].getMIValue();
|
||||||
if (value instanceof MIConst) {
|
if (value instanceof MIConst) {
|
||||||
String reason = ((MIConst)value).getString();
|
String reason = ((MIConst) value).getString();
|
||||||
MIEvent event = createEvent(reason, rr);
|
MIEvent event = createEvent(reason, rr);
|
||||||
if (event != null) {
|
if (event != null) {
|
||||||
list.add(event);
|
list.add(event);
|
||||||
|
@ -330,9 +346,10 @@ public class RxThread extends Thread {
|
||||||
event = new MIBreakpointHitEvent(rr);
|
event = new MIBreakpointHitEvent(rr);
|
||||||
}
|
}
|
||||||
session.getMIInferior().setSuspended();
|
session.getMIInferior().setSuspended();
|
||||||
} else if ("watchpoint-trigger".equals(reason) ||
|
} else if (
|
||||||
"read-watchpoint-trigger".equals(reason) ||
|
"watchpoint-trigger".equals(reason)
|
||||||
"access-watchpoint-trigger".equals(reason)) {
|
|| "read-watchpoint-trigger".equals(reason)
|
||||||
|
|| "access-watchpoint-trigger".equals(reason)) {
|
||||||
if (exec != null) {
|
if (exec != null) {
|
||||||
event = new MIWatchpointTriggerEvent(exec);
|
event = new MIWatchpointTriggerEvent(exec);
|
||||||
} else if (rr != null) {
|
} else if (rr != null) {
|
||||||
|
@ -374,8 +391,7 @@ public class RxThread extends Thread {
|
||||||
event = new MIFunctionFinishedEvent(rr);
|
event = new MIFunctionFinishedEvent(rr);
|
||||||
}
|
}
|
||||||
session.getMIInferior().setSuspended();
|
session.getMIInferior().setSuspended();
|
||||||
} else if ("exited-normally".equals(reason) ||
|
} else if ("exited-normally".equals(reason) || "exited".equals(reason)) {
|
||||||
"exited".equals(reason)) {
|
|
||||||
if (exec != null) {
|
if (exec != null) {
|
||||||
event = new MIInferiorExitEvent(exec);
|
event = new MIInferiorExitEvent(exec);
|
||||||
} else if (rr != null) {
|
} else if (rr != null) {
|
||||||
|
@ -393,4 +409,18 @@ public class RxThread extends Thread {
|
||||||
return event;
|
return event;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String[] getStreamRecords() {
|
||||||
|
List streamRecords = new ArrayList();
|
||||||
|
MIOOBRecord[] oobRecords = (MIOOBRecord[]) oobList.toArray(new MIOOBRecord[0]);
|
||||||
|
for (int i = 0; i < oobRecords.length; i++) {
|
||||||
|
if (oobRecords[i] instanceof MIStreamRecord) {
|
||||||
|
String s = ((MIStreamRecord) oobRecords[i]).getString().trim();
|
||||||
|
if (s != null && s.length() > 0) {
|
||||||
|
streamRecords.add(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (String[]) streamRecords.toArray(new String[0]);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ import org.eclipse.cdt.debug.mi.core.cdi.BreakpointHit;
|
||||||
import org.eclipse.cdt.debug.mi.core.cdi.EndSteppingRange;
|
import org.eclipse.cdt.debug.mi.core.cdi.EndSteppingRange;
|
||||||
import org.eclipse.cdt.debug.mi.core.cdi.ErrorInfo;
|
import org.eclipse.cdt.debug.mi.core.cdi.ErrorInfo;
|
||||||
import org.eclipse.cdt.debug.mi.core.cdi.Session;
|
import org.eclipse.cdt.debug.mi.core.cdi.Session;
|
||||||
|
import org.eclipse.cdt.debug.mi.core.cdi.SharedLibraryEvent;
|
||||||
import org.eclipse.cdt.debug.mi.core.cdi.SignalReceived;
|
import org.eclipse.cdt.debug.mi.core.cdi.SignalReceived;
|
||||||
import org.eclipse.cdt.debug.mi.core.cdi.WatchpointScope;
|
import org.eclipse.cdt.debug.mi.core.cdi.WatchpointScope;
|
||||||
import org.eclipse.cdt.debug.mi.core.cdi.WatchpointTrigger;
|
import org.eclipse.cdt.debug.mi.core.cdi.WatchpointTrigger;
|
||||||
|
@ -21,6 +22,7 @@ import org.eclipse.cdt.debug.mi.core.event.MIErrorEvent;
|
||||||
import org.eclipse.cdt.debug.mi.core.event.MIEvent;
|
import org.eclipse.cdt.debug.mi.core.event.MIEvent;
|
||||||
import org.eclipse.cdt.debug.mi.core.event.MIFunctionFinishedEvent;
|
import org.eclipse.cdt.debug.mi.core.event.MIFunctionFinishedEvent;
|
||||||
import org.eclipse.cdt.debug.mi.core.event.MILocationReachedEvent;
|
import org.eclipse.cdt.debug.mi.core.event.MILocationReachedEvent;
|
||||||
|
import org.eclipse.cdt.debug.mi.core.event.MISharedLibEvent;
|
||||||
import org.eclipse.cdt.debug.mi.core.event.MISignalEvent;
|
import org.eclipse.cdt.debug.mi.core.event.MISignalEvent;
|
||||||
import org.eclipse.cdt.debug.mi.core.event.MISteppingRangeEvent;
|
import org.eclipse.cdt.debug.mi.core.event.MISteppingRangeEvent;
|
||||||
import org.eclipse.cdt.debug.mi.core.event.MIWatchpointScopeEvent;
|
import org.eclipse.cdt.debug.mi.core.event.MIWatchpointScopeEvent;
|
||||||
|
@ -56,6 +58,8 @@ public class SuspendedEvent implements ICDISuspendedEvent {
|
||||||
return new EndSteppingRange(session);
|
return new EndSteppingRange(session);
|
||||||
} else if (event instanceof MIErrorEvent) {
|
} else if (event instanceof MIErrorEvent) {
|
||||||
return new ErrorInfo(session, (MIErrorEvent)event);
|
return new ErrorInfo(session, (MIErrorEvent)event);
|
||||||
|
} else if (event instanceof MISharedLibEvent) {
|
||||||
|
return new SharedLibraryEvent(session);
|
||||||
}
|
}
|
||||||
return session;
|
return session;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue