1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-06 17:26:01 +02:00

Bug 294538 - Debug launch takes 20 extra sec (CLI problem)

This commit is contained in:
Ken Ryall 2010-02-03 22:30:15 +00:00
parent 1d7bf46ba1
commit 1ce33a5af6
4 changed files with 220 additions and 1 deletions

View file

@ -0,0 +1,83 @@
/*******************************************************************************
* Copyright (c) 2007, 2010 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
* Marc-Andre Laperle - Replace info proc with info pid, patch for bug 294538
*******************************************************************************/
package org.eclipse.cdt.debug.mi.core.command.factories.macos;
import org.eclipse.cdt.debug.mi.core.MIException;
import org.eclipse.cdt.debug.mi.core.command.CLIInfoProc;
import org.eclipse.cdt.debug.mi.core.output.CLIInfoProcInfo;
import org.eclipse.cdt.debug.mi.core.output.MIInfo;
import org.eclipse.cdt.debug.mi.core.output.MIOutput;
import org.eclipse.cdt.debug.mi.core.output.MIResult;
/**
* GDB/CLI info proc parsing. 18 info pid &"info pid\n"
* 18^done,process-id="89643"
*
*/
class MacOSCLIInfoPID extends CLIInfoProc {
// apple-gdb doesn't have info proc but has info pid
// Since info proc is only used to get the pid, it is valid to use info pid
// as a replacement
public MacOSCLIInfoPID() {
setOperation("info pid"); //$NON-NLS-1$
}
public MIInfo getMIInfo() throws MIException {
MIInfo info = null;
MIOutput out = getMIOutput();
if (out != null) {
info = new MacOSCLIInfoPIDOutput(out);
if (info.isError()) {
throwMIException(info, out);
}
}
return info;
}
class MacOSCLIInfoPIDOutput extends CLIInfoProcInfo {
int pid;
public MacOSCLIInfoPIDOutput(MIOutput out) {
super(out);
parsePID();
}
void parsePID() {
if (isDone()) {
MIOutput out = getMIOutput();
MIResult[] rr = out.getMIResultRecord().getMIResults();
for (int i = 0; i < rr.length; i++) {
parsePIDLine(rr[i].toString());
}
}
}
void parsePIDLine(String str) {
if (str != null && str.length() > 0) {
str = str.trim();
if (!str.startsWith("process-id=")) { //$NON-NLS-1$
return;
}
pid = Integer.decode(str.substring(12, str.length() - 1))
.intValue();
}
}
public int getPID() {
return pid;
}
}
}

View file

@ -0,0 +1,50 @@
/*******************************************************************************
* Copyright (c) 2000, 2010 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* QNX Software Systems - Initial API and implementation
* Marc-Andre Laperle - use -thread-list-ids for mac, fix for bug 294538
*******************************************************************************/
package org.eclipse.cdt.debug.mi.core.command.factories.macos;
import org.eclipse.cdt.debug.mi.core.MIException;
import org.eclipse.cdt.debug.mi.core.command.CLIInfoThreads;
import org.eclipse.cdt.debug.mi.core.output.CLIInfoThreadsInfo;
import org.eclipse.cdt.debug.mi.core.output.MIInfo;
import org.eclipse.cdt.debug.mi.core.output.MIOutput;
class MacOSCLIInfoThreads extends CLIInfoThreads {
public MacOSCLIInfoThreads() {
super();
// with apple-gdb, we use -thread-list-ids as a replacement for info
// threads
setOperation("-thread-list-ids"); //$NON-NLS-1$
}
// MI doesn't work with a space between the token and the
// operation, so we override CLICommmand's toString
public String toString() {
return getToken() + getOperation() + "\n"; //$NON-NLS-1$
}
public MIInfo getMIInfo() throws MIException {
MIInfo info = null;
MIOutput out = getMIOutput();
if (out != null) {
info = new MacOsCLIInfoThreadsInfo(out);
if (info.isError()) {
throwMIException(info, out);
}
}
return info;
}
public CLIInfoThreadsInfo getMIInfoThreadsInfo() throws MIException {
return (CLIInfoThreadsInfo) getMIInfo();
}
}

View file

@ -0,0 +1,77 @@
/*******************************************************************************
* Copyright (c) 2000, 2010 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* QNX Software Systems - Initial API and implementation
* Marc-Andre Laperle - use -thread-list-ids for mac, fix for bug 294538
*******************************************************************************/
package org.eclipse.cdt.debug.mi.core.command.factories.macos;
import java.util.Arrays;
import org.eclipse.cdt.debug.mi.core.output.CLIInfoThreadsInfo;
import org.eclipse.cdt.debug.mi.core.output.MIConst;
import org.eclipse.cdt.debug.mi.core.output.MIOutput;
import org.eclipse.cdt.debug.mi.core.output.MIResult;
import org.eclipse.cdt.debug.mi.core.output.MIResultRecord;
import org.eclipse.cdt.debug.mi.core.output.MITuple;
import org.eclipse.cdt.debug.mi.core.output.MIValue;
/**
* This class actually parses -thread-list-ids and converts it to the
* CLIInfoThreadsInfo 'format'
*/
class MacOsCLIInfoThreadsInfo extends CLIInfoThreadsInfo {
public MacOsCLIInfoThreadsInfo(MIOutput out) {
super(out);
}
protected void parse() {
if (isDone()) {
MIOutput out = getMIOutput();
MIResultRecord rr = out.getMIResultRecord();
if (rr != null) {
MIResult[] results = rr.getMIResults();
for (int i = 0; i < results.length; i++) {
String var = results[i].getVariable();
if (var.equals("thread-ids")) { //$NON-NLS-1$
MIValue val = results[i].getMIValue();
if (val instanceof MITuple) {
parseThreadIds((MITuple) val);
}
}
}
}
}
if (threadIds == null) {
threadIds = new int[0];
}
Arrays.sort(threadIds);
if (threadIds.length > 0) {
currentThreadId = threadIds[0];
}
}
void parseThreadIds(MITuple tuple) {
MIResult[] results = tuple.getMIResults();
threadIds = new int[results.length];
for (int i = 0; i < results.length; i++) {
String var = results[i].getVariable();
if (var.equals("thread-id")) { //$NON-NLS-1$
MIValue value = results[i].getMIValue();
if (value instanceof MIConst) {
String str = ((MIConst) value).getCString();
try {
threadIds[i] = Integer.parseInt(str.trim());
} catch (NumberFormatException e) {
}
}
}
}
}
}

View file

@ -7,12 +7,14 @@
*
* Contributors:
* Nokia - Initial API and implementation
* Marc-Andre Laperle - patch for bug #250037
* Marc-Andre Laperle - patch for bug #250037, 294538
*******************************************************************************/
package org.eclipse.cdt.debug.mi.core.command.factories.macos;
import java.io.File;
import org.eclipse.cdt.debug.mi.core.command.CLIInfoProc;
import org.eclipse.cdt.debug.mi.core.command.CLIInfoThreads;
import org.eclipse.cdt.debug.mi.core.command.MIEnvironmentCD;
import org.eclipse.cdt.debug.mi.core.command.MIInfoSharedLibrary;
import org.eclipse.cdt.debug.mi.core.command.MIVarUpdate;
@ -54,5 +56,12 @@ public class StandardMacOSCommandFactory extends StandardCommandFactory {
return new MacOSMIVarUpdate(getMIVersion(), name);
}
public CLIInfoProc createCLIInfoProc() {
return new MacOSCLIInfoPID();
}
public CLIInfoThreads createCLIInfoThreads() {
return new MacOSCLIInfoThreads();
}
}