mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 22:52:11 +02:00
Make sure gdb is ready to receive commnad
before creating the MISession.
This commit is contained in:
parent
8bc64c6f3c
commit
82e8f08353
1 changed files with 81 additions and 3 deletions
|
@ -4,8 +4,12 @@
|
|||
*/
|
||||
package org.eclipse.cdt.debug.mi.core;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.text.MessageFormat;
|
||||
|
||||
import org.eclipse.cdt.debug.core.cdi.ICDISession;
|
||||
|
@ -131,7 +135,8 @@ public class MIPlugin extends Plugin {
|
|||
}
|
||||
}
|
||||
|
||||
Process pgdb = ProcessFactory.getFactory().exec(args);
|
||||
Process pgdb = getGDBProcess(args, program);
|
||||
|
||||
MISession session;
|
||||
try {
|
||||
session = createMISession(pgdb, pty, MISession.PROGRAM);
|
||||
|
@ -181,7 +186,7 @@ public class MIPlugin extends Plugin {
|
|||
} else {
|
||||
args = new String[] {gdb, "--cd="+cwd.getAbsolutePath(), "--command="+gdbinit, "--quiet", "-nw", "-i", "mi1", "-c", core.getAbsolutePath(), program.getAbsolutePath()};
|
||||
}
|
||||
Process pgdb = ProcessFactory.getFactory().exec(args);
|
||||
Process pgdb = getGDBProcess(args, program);
|
||||
MISession session;
|
||||
try {
|
||||
session = createMISession(pgdb, null, MISession.CORE);
|
||||
|
@ -214,7 +219,7 @@ public class MIPlugin extends Plugin {
|
|||
} else {
|
||||
args = new String[] {gdb, "--cd="+cwd.getAbsolutePath(), "--command="+gdbinit, "--quiet", "-nw", "-i", "mi1", program.getAbsolutePath()};
|
||||
}
|
||||
Process pgdb = ProcessFactory.getFactory().exec(args);
|
||||
Process pgdb = getGDBProcess(args, program);
|
||||
MISession session;
|
||||
try {
|
||||
session = createMISession(pgdb, null, MISession.ATTACH);
|
||||
|
@ -283,6 +288,79 @@ public class MIPlugin extends Plugin {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the session timeout.
|
||||
*
|
||||
* Allow at least one second per megabyte as a minimum on the timeout
|
||||
* (note one second is an arbitrary choice based on swapping performance).
|
||||
* This is required for loading the symbols from very large programs.
|
||||
*/
|
||||
private int getAdjustedTimeout(File program) {
|
||||
Preferences prefs = plugin.getPluginPreferences();
|
||||
int timeout = prefs.getInt(IMIConstants.PREF_REQUEST_TIMEOUT); //milliseconds
|
||||
if(program != null && program.exists()) {
|
||||
long programSize = program.length();
|
||||
int minimumTimeout = (int)(programSize / 1000L);
|
||||
if(timeout < minimumTimeout) {
|
||||
//debugLog("Adjusting timeout from " + timeout + "ms to " + minimumTimeout + "ms");
|
||||
timeout = minimumTimeout;
|
||||
}
|
||||
}
|
||||
return timeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Do some basic synchronisation, gdb make take some time to load
|
||||
* for whatever reasons.
|
||||
* @param args
|
||||
* @param program
|
||||
* @return Process
|
||||
* @throws IOException
|
||||
*/
|
||||
protected Process getGDBProcess(String[] args, File program) throws IOException {
|
||||
final Process pgdb = ProcessFactory.getFactory().exec(args);
|
||||
Thread syncStartup = new Thread("GDB Start") {
|
||||
public void run() {
|
||||
try {
|
||||
String line;
|
||||
InputStream stream = pgdb.getInputStream();
|
||||
Reader r = new InputStreamReader(stream);
|
||||
BufferedReader reader = new BufferedReader(r);
|
||||
while ((line = reader.readLine()) != null) {
|
||||
line = line.trim();
|
||||
//System.out.println("GDB " + line);
|
||||
if (line.startsWith("(gdb)")) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// Do nothing
|
||||
}
|
||||
synchronized (pgdb) {
|
||||
pgdb.notifyAll();
|
||||
}
|
||||
}
|
||||
};
|
||||
syncStartup.start();
|
||||
|
||||
synchronized (pgdb) {
|
||||
int timeout = getAdjustedTimeout(program);
|
||||
while (syncStartup.isAlive()) {
|
||||
try {
|
||||
pgdb.wait(timeout);
|
||||
break;
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
try {
|
||||
syncStartup.interrupt();
|
||||
syncStartup.join(1000);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
return pgdb;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.core.runtime.Plugin#startup()
|
||||
*/
|
||||
|
|
Loading…
Add table
Reference in a new issue