1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Fix for 190277: Stopping a debugg session causes all user processes to terminate (Patch by Piotr Kundu)

This commit is contained in:
Anton Leherbauer 2007-09-06 11:56:01 +00:00
parent 2a22f9e8d9
commit 39180b7960
5 changed files with 155 additions and 12 deletions

View file

@ -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 {

View file

@ -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;
}
}

View file

@ -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();
}

View file

@ -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) {
}
}
}
}
}
}

View file

@ -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();