use of org.eclipse.che.api.debug.shared.model.Location in project che by eclipse.
the class Gdb method suspend.
public Location suspend(final String file, boolean isRemoteConnection) throws IOException, InterruptedException, DebuggerException {
if (pid < 0) {
throw new DebuggerException("Gdb process not found.");
}
if (isRemoteConnection) {
Runtime.getRuntime().exec("kill -SIGINT " + pid).waitFor();
sendCommand("signal SIGSTOP ");
} else {
final List<String> outputs = new ArrayList<>();
final ProcessBuilder processBuilder = new ProcessBuilder().command("ps", "-o", "pid,cmd", "--ppid", String.valueOf(pid));
final Process process = processBuilder.start();
LineConsumer stdout = new AbstractLineConsumer() {
@Override
public void writeLine(String line) throws IOException {
outputs.add(line);
}
};
ProcessUtil.process(process, stdout);
int processId = -1;
for (String output : outputs) {
try {
final ProcessInfo processInfo = ProcessInfo.parse(output);
if (file.equals(processInfo.getProcessName())) {
processId = processInfo.getProcessId();
}
} catch (Exception e) {
//we can't get info about current process, but we are trying to get info about another processes
}
}
if (processId == -1) {
throw new DebuggerException(format("Process %s not found.", file));
}
Runtime.getRuntime().exec("kill -SIGINT " + processId).waitFor();
}
final GdbOutput gdbOutput = sendCommand("backtrace");
final GdbBacktrace backtrace = GdbBacktrace.parse(gdbOutput);
final Map<Integer, Location> frames = backtrace.getFrames();
if (frames.containsKey(0)) {
return frames.get(0);
}
throw new DebuggerException("Unable recognize current location for debugger session. ");
}
use of org.eclipse.che.api.debug.shared.model.Location in project che by eclipse.
the class GdbBacktraceTest method testParseFileLocation.
@Test
public void testParseFileLocation() throws Exception {
GdbOutput gdbOutput = GdbOutput.of(BACKTRACE_OUTPUT);
GdbBacktrace backtrace = GdbBacktrace.parse(gdbOutput);
Map<Integer, Location> frames = backtrace.getFrames();
Location frame0 = frames.get(0);
Location frame3 = frames.get(3);
assertEquals(frame0.getTarget(), "../sysdeps/unix/syscall-template.S");
assertEquals(frame0.getLineNumber(), 81);
assertEquals(frame3.getTarget(), "hello.cc");
assertEquals(frame3.getLineNumber(), 16);
}
use of org.eclipse.che.api.debug.shared.model.Location in project che by eclipse.
the class GdbInfoLineTest method testParse2.
@Test
public void testParse2() throws Exception {
GdbOutput gdbOutput = GdbOutput.of("Line 530 of \"/usr/src/debug/gcc-4.8.3-20140911/obj-x86_64-redhat-linux/x86_64-redhat-linux/libstdc++-v3/include/ostream\"\n" + " starts at address 0x3e8ba94e60 <std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)>\n" + " and ends at 0x3e8ba94e6c <std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)+12>.\n");
GdbInfoLine gdbInfoLine = GdbInfoLine.parse(gdbOutput);
Location location = gdbInfoLine.getLocation();
assertEquals(location.getTarget(), "/usr/src/debug/gcc-4.8.3-20140911/obj-x86_64-redhat-linux/x86_64-redhat-linux/libstdc++-v3/include/ostream");
assertEquals(location.getLineNumber(), 530);
}
use of org.eclipse.che.api.debug.shared.model.Location in project che by eclipse.
the class GdbInfoLineTest method testParse3.
@Test
public void testParse3() throws Exception {
GdbOutput gdbOutput = GdbOutput.of("Line number 34 is out of range for \"artic_adc.c\"");
GdbInfoLine gdbInfoLine = GdbInfoLine.parse(gdbOutput);
Location location = gdbInfoLine.getLocation();
assertEquals(location.getTarget(), "artic_adc.c");
assertEquals(location.getLineNumber(), 34);
}
use of org.eclipse.che.api.debug.shared.model.Location in project che by eclipse.
the class GdbInfoBreak method parse.
/**
* Factory method.
*/
public static GdbInfoBreak parse(GdbOutput gdbOutput) throws GdbParseException {
String output = gdbOutput.getOutput();
List<Breakpoint> breakpoints = new ArrayList<>();
for (String line : output.split("\n")) {
Matcher matcher = GDB_INFO_B.matcher(line);
if (matcher.find()) {
String file = matcher.group(2);
String lineNumber = matcher.group(3);
Location location = new LocationImpl(file, Integer.parseInt(lineNumber));
breakpoints.add(new BreakpointImpl(location));
}
}
return new GdbInfoBreak(breakpoints);
}
Aggregations