diff --git a/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/MIInferior.java b/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/MIInferior.java index 7c30a97856b..c685a52fb60 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/MIInferior.java +++ b/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/MIInferior.java @@ -8,6 +8,7 @@ * Contributors: * QNX Software Systems - Initial API and implementation * Hewlett-Packard Development Company - fix for bug 109733 + * ENEA Software AB - CLI command extension - fix for bug 190277 *******************************************************************************/ package org.eclipse.cdt.debug.mi.core; @@ -21,9 +22,11 @@ import org.eclipse.cdt.debug.mi.core.command.CommandFactory; import org.eclipse.cdt.debug.mi.core.command.CLIExecAbort; import org.eclipse.cdt.debug.mi.core.command.MIExecInterrupt; import org.eclipse.cdt.debug.mi.core.command.MIGDBShowExitCode; +import org.eclipse.cdt.debug.mi.core.command.CLIInfoProc; import org.eclipse.cdt.debug.mi.core.command.CLIInfoProgram; import org.eclipse.cdt.debug.mi.core.event.MIInferiorExitEvent; import org.eclipse.cdt.debug.mi.core.output.MIGDBShowExitCodeInfo; +import org.eclipse.cdt.debug.mi.core.output.CLIInfoProcInfo; import org.eclipse.cdt.debug.mi.core.output.CLIInfoProgramInfo; /** @@ -328,15 +331,27 @@ public class MIInferior extends Process { int pid = 0; // Do not try this on attach session. if (!isConnected()) { - // Try to discover the pid + // Try to discover the pid using GDB/CLI Command "info proc" CommandFactory factory = session.getCommandFactory(); - CLIInfoProgram prog = factory.createCLIInfoProgram(); + CLIInfoProc proc = factory.createCLIInfoProc(); try { RxThread rxThread = session.getRxThread(); rxThread.setEnableConsole(false); + session.postCommand(proc); + CLIInfoProcInfo infoProc = proc.getMIInfoProcInfo(); + pid = infoProc.getPID(); + } catch (MIException e) { + // no rethrown. + } + + // Try to discover the pid using GDB/CLI Command "info program" if "info proc" failed + try { + if(pid <= 0){ + CLIInfoProgram prog = factory.createCLIInfoProgram(); session.postCommand(prog); CLIInfoProgramInfo info = prog.getMIInfoProgramInfo(); pid = info.getPID(); + } } catch (MIException e) { // no rethrown. } finally { diff --git a/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/command/CLIInfoProc.java b/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/command/CLIInfoProc.java new file mode 100644 index 00000000000..f9cf396cbcb --- /dev/null +++ b/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/command/CLIInfoProc.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (c) 2007 ENEA Software AB and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * ENEA Software AB - CLI command extension - fix for bug 190277 + *******************************************************************************/ + +package org.eclipse.cdt.debug.mi.core.command; + +import org.eclipse.cdt.debug.mi.core.MIException; +import org.eclipse.cdt.debug.mi.core.output.MIInfo; +import org.eclipse.cdt.debug.mi.core.output.CLIInfoProcInfo; +import org.eclipse.cdt.debug.mi.core.output.MIOutput; + +/** + * + * info proc + * + */ +public class CLIInfoProc extends CLICommand +{ + public CLIInfoProc() { + super("info proc"); //$NON-NLS-1$ + } + + public CLIInfoProcInfo getMIInfoProcInfo() throws MIException { + return (CLIInfoProcInfo)getMIInfo(); + } + + public MIInfo getMIInfo() throws MIException { + MIInfo info = null; + MIOutput out = getMIOutput(); + if (out != null) { + info = new CLIInfoProcInfo(out); + if (info.isError()) { + throwMIException(info, out); + } + } + return info; + } +} diff --git a/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/command/CommandFactory.java b/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/command/CommandFactory.java index 9d2fc3ee09c..5bb36966796 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/command/CommandFactory.java +++ b/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/command/CommandFactory.java @@ -7,6 +7,7 @@ * * Contributors: * QNX Software Systems - Initial API and implementation + * ENEA Software AB - CLI command extension - fix for bug 190277 *******************************************************************************/ package org.eclipse.cdt.debug.mi.core.command; @@ -45,7 +46,7 @@ public class CommandFactory { public MIBreakAfter createMIBreakAfter(int brknum, int count) { return new MIBreakAfter(getMIVersion(), brknum, count); } - + public MIBreakCondition createMIBreakCondition (int brknum, String expr) { return new MIBreakCondition(getMIVersion(), brknum, expr); } @@ -307,13 +308,13 @@ public class CommandFactory { return new MITargetDetach(getMIVersion()); } - public MITargetDownload createMITargetDownload(String file) { - return new MITargetDownload(getMIVersion(), file); - } + public MITargetDownload createMITargetDownload(String file) { + return new MITargetDownload(getMIVersion(), file); + } - public MITargetSelect createMITargetSelect(String[] params) { - return new MITargetSelect(getMIVersion(), params); - } + public MITargetSelect createMITargetSelect(String[] params) { + return new MITargetSelect(getMIVersion(), params); + } public MIThreadListIds createMIThreadListIds() { return new MIThreadListIds(getMIVersion()); @@ -363,6 +364,10 @@ public class CommandFactory { return new CLIPType(name); } + public CLIInfoProc createCLIInfoProc() { + return new CLIInfoProc(); + } + public CLIInfoProgram createCLIInfoProgram() { return new CLIInfoProgram(); } diff --git a/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/output/CLIInfoProcInfo.java b/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/output/CLIInfoProcInfo.java new file mode 100644 index 00000000000..01c9f2d0cd1 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/output/CLIInfoProcInfo.java @@ -0,0 +1,74 @@ +/******************************************************************************* + * Copyright (c) 2007 ENEA Software AB and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * ENEA Software AB - CLI command extension - fix for bug 190277 + *******************************************************************************/ + +package org.eclipse.cdt.debug.mi.core.output; + +import java.util.StringTokenizer; + + +/** + * GDB/CLI info proc parsing. +(gdb) info proc +process 19127 flags: +PR_STOPPED Process (LWP) is stopped +PR_ISTOP Stopped on an event of interest +PR_RLC Run-on-last-close is in effect +PR_FAULTED : Incurred a traced hardware fault FLTBPT: Breakpoint trap + */ +public class CLIInfoProcInfo extends MIInfo { + + int pid; + + public CLIInfoProcInfo(MIOutput out) { + super(out); + parse(); + } + + public int getPID() { + return pid; + } + + void parse() { + if (isDone()) { + MIOutput out = getMIOutput(); + MIOOBRecord[] oobs = out.getMIOOBRecords(); + for (int i = 0; i < oobs.length; i++) { + if (oobs[i] instanceof MIConsoleStreamOutput) { + MIStreamRecord cons = (MIStreamRecord) oobs[i]; + String str = cons.getString(); + // We are interested in the process info and PID + parseLine(str); + } + } + } + } + + void parseLine(String str) { + if (str != null && str.length() > 0) { + str = str.trim(); + if (!str.startsWith("process")) { //$NON-NLS-1$ + return; + } + StringTokenizer st = new StringTokenizer(str); + while (st.hasMoreTokens()) { + String s = st.nextToken(); + if (Character.isDigit(s.charAt(0))) { + try { + pid = Integer.decode(s).intValue(); + break; + } catch (NumberFormatException e) { + } + } + } + } + } + +} diff --git a/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/output/CLIInfoProgramInfo.java b/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/output/CLIInfoProgramInfo.java index 3fe8cc6f3f5..c86be5772bd 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/output/CLIInfoProgramInfo.java +++ b/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/output/CLIInfoProgramInfo.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 QNX Software Systems and others. + * Copyright (c) 2000, 2007 QNX Software Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * QNX Software Systems - Initial API and implementation + * ENEA Software AB - CLI command extension - fix for bug 190277 *******************************************************************************/ package org.eclipse.cdt.debug.mi.core.output; @@ -15,7 +16,7 @@ import java.util.StringTokenizer; /** * GDB/MI info program parsing. -(gdb) +(gdb) info program &"info program\n" ~"\tUsing the running image of child process 21301.\n" @@ -23,7 +24,7 @@ info program ~"It stopped at breakpoint 1.\n" ~"Type \"info stack\" or \"info registers\" for more information.\n" ^done -(gdb) +(gdb) */ public class CLIInfoProgramInfo extends MIInfo { @@ -62,6 +63,9 @@ public class CLIInfoProgramInfo extends MIInfo { StringTokenizer st = new StringTokenizer(str); while (st.hasMoreTokens()) { String s = st.nextToken(); + /* Not a process id if LWP is reported */ + if (s.equals("LWP")) break; //$NON-NLS-1$ + if (Character.isDigit(s.charAt(0))) { try { pid = Integer.decode(s).intValue();