1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-07 09:46:02 +02:00

Cache the stackframes to reduce the chatting between

GDB.
This commit is contained in:
Alain Magloire 2004-01-23 04:05:09 +00:00
parent e35bc93925
commit 74d7916ebc
2 changed files with 112 additions and 79 deletions

View file

@ -1,3 +1,10 @@
2004-12-22 Alain Magloire
Cache the stackframes when we become suspended, to reduce
the chat between gdb.
* src/org/eclipse/cdt/debug/mi/core/cdi/model/Thread.java
2003-12-22 Mikhail Khodjaiants 2003-12-22 Mikhail Khodjaiants
Fix for bug 49282 terminate the gdb session if the termination of the inferior fails. Fix for bug 49282 terminate the gdb session if the termination of the inferior fails.

View file

@ -5,6 +5,9 @@
*/ */
package org.eclipse.cdt.debug.mi.core.cdi.model; package org.eclipse.cdt.debug.mi.core.cdi.model;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.cdt.debug.core.cdi.CDIException; import org.eclipse.cdt.debug.core.cdi.CDIException;
import org.eclipse.cdt.debug.core.cdi.ICDILocation; import org.eclipse.cdt.debug.core.cdi.ICDILocation;
import org.eclipse.cdt.debug.core.cdi.model.ICDISignal; import org.eclipse.cdt.debug.core.cdi.model.ICDISignal;
@ -33,8 +36,11 @@ public class Thread extends CObject implements ICDIThread {
static ICDIStackFrame[] noStack = new ICDIStackFrame[0]; static ICDIStackFrame[] noStack = new ICDIStackFrame[0];
int id; int id;
ICDIStackFrame currentFrame; ICDIStackFrame currentFrame;
List currentFrames;
int stackdepth = 0; int stackdepth = 0;
final static int STACKFRAME_DEFAULT_DEPTH = 200;
public Thread(ICDITarget target, int threadId) { public Thread(ICDITarget target, int threadId) {
super(target); super(target);
id = threadId; id = threadId;
@ -47,6 +53,7 @@ public class Thread extends CObject implements ICDIThread {
public void clearState() { public void clearState() {
stackdepth = 0; stackdepth = 0;
currentFrame = null; currentFrame = null;
currentFrames = null;
} }
public String toString() { public String toString() {
@ -74,8 +81,13 @@ public class Thread extends CObject implements ICDIThread {
* @see org.eclipse.cdt.debug.core.cdi.model.ICDIThread#getStackFrames() * @see org.eclipse.cdt.debug.core.cdi.model.ICDIThread#getStackFrames()
*/ */
public ICDIStackFrame[] getStackFrames() throws CDIException { public ICDIStackFrame[] getStackFrames() throws CDIException {
int depth = 0;
ICDIStackFrame[] stacks = noStack; // get the frames depth
int depth = getStackFrameCount();
// refresh if we have nothing or if we have just a subset get everything.
if (currentFrames == null || currentFrames.size() < depth) {
currentFrames = new ArrayList();
Session session = (Session) getTarget().getSession(); Session session = (Session) getTarget().getSession();
Target currentTarget = (Target) session.getCurrentTarget(); Target currentTarget = (Target) session.getCurrentTarget();
ICDIThread currentThread = currentTarget.getCurrentThread(); ICDIThread currentThread = currentTarget.getCurrentThread();
@ -84,16 +96,14 @@ public class Thread extends CObject implements ICDIThread {
MISession mi = session.getMISession(); MISession mi = session.getMISession();
CommandFactory factory = mi.getCommandFactory(); CommandFactory factory = mi.getCommandFactory();
MIStackListFrames frames = factory.createMIStackListFrames(); MIStackListFrames frames = factory.createMIStackListFrames();
depth = getStackFrameCount();
mi.postCommand(frames); mi.postCommand(frames);
MIStackListFramesInfo info = frames.getMIStackListFramesInfo(); MIStackListFramesInfo info = frames.getMIStackListFramesInfo();
if (info == null) { if (info == null) {
throw new CDIException("No answer"); throw new CDIException("No answer");
} }
MIFrame[] miFrames = info.getMIFrames(); MIFrame[] miFrames = info.getMIFrames();
stacks = new StackFrame[miFrames.length]; for (int i = 0; i < miFrames.length; i++) {
for (int i = 0; i < stacks.length; i++) { currentFrames.add(new StackFrame(this, miFrames[i], depth - miFrames[i].getLevel()));
stacks[i] = new StackFrame(this, miFrames[i], depth - miFrames[i].getLevel());
} }
} catch (MIException e) { } catch (MIException e) {
//throw new CDIException(e.getMessage()); //throw new CDIException(e.getMessage());
@ -104,14 +114,17 @@ public class Thread extends CObject implements ICDIThread {
} finally { } finally {
currentTarget.setCurrentThread(currentThread, false); currentTarget.setCurrentThread(currentThread, false);
} }
// assign the currentFrame if it was not done yet.
if (currentFrame == null) { if (currentFrame == null) {
for (int i = 0; i < stacks.length; i++) { for (int i = 0; i < currentFrames.size(); i++) {
if (stacks[i].getLevel() == depth) { ICDIStackFrame stack = (ICDIStackFrame) currentFrames.get(i);
currentFrame = stacks[i]; if (stack.getLevel() == depth) {
currentFrame = stack;
} }
} }
} }
return stacks; }
return (ICDIStackFrame[]) currentFrames.toArray(noStack);
} }
/** /**
@ -162,25 +175,35 @@ public class Thread extends CObject implements ICDIThread {
* @see org.eclipse.cdt.debug.core.cdi.model.ICDIThread#getStackFrames() * @see org.eclipse.cdt.debug.core.cdi.model.ICDIThread#getStackFrames()
*/ */
public ICDIStackFrame[] getStackFrames(int low, int high) throws CDIException { public ICDIStackFrame[] getStackFrames(int low, int high) throws CDIException {
ICDIStackFrame[] stacks = noStack; if (currentFrames == null || currentFrames.size() < high) {
currentFrames = new ArrayList();
Session session = (Session) getTarget().getSession(); Session session = (Session) getTarget().getSession();
Target currentTarget = (Target) session.getCurrentTarget(); Target currentTarget = (Target) session.getCurrentTarget();
ICDIThread currentThread = currentTarget.getCurrentThread(); ICDIThread currentThread = currentTarget.getCurrentThread();
currentTarget.setCurrentThread(this, false); currentTarget.setCurrentThread(this, false);
try { try {
int depth = getStackFrameCount();
int upperBound;
// try to get the largest subset.
// if what the user asks is smaller then the depth
// try to cache things by getting the min(depth,STACKFRAME_DEFAULT_DEPTH)
// else give fetch the entire thing.
if (high < depth) {
upperBound = Math.min(depth, STACKFRAME_DEFAULT_DEPTH);
} else {
upperBound = depth;
}
MISession mi = session.getMISession(); MISession mi = session.getMISession();
CommandFactory factory = mi.getCommandFactory(); CommandFactory factory = mi.getCommandFactory();
MIStackListFrames frames = factory.createMIStackListFrames(low, high); MIStackListFrames frames = factory.createMIStackListFrames(0, upperBound);
int depth = getStackFrameCount();
mi.postCommand(frames); mi.postCommand(frames);
MIStackListFramesInfo info = frames.getMIStackListFramesInfo(); MIStackListFramesInfo info = frames.getMIStackListFramesInfo();
if (info == null) { if (info == null) {
throw new CDIException("No answer"); throw new CDIException("No answer");
} }
MIFrame[] miFrames = info.getMIFrames(); MIFrame[] miFrames = info.getMIFrames();
stacks = new StackFrame[miFrames.length]; for (int i = 0; i < miFrames.length; i++) {
for (int i = 0; i < stacks.length; i++) { currentFrames.add(new StackFrame(this, miFrames[i], depth - miFrames[i].getLevel()));
stacks[i] = new StackFrame(this, miFrames[i], depth - miFrames[i].getLevel());
} }
} catch (MIException e) { } catch (MIException e) {
//throw new CDIException(e.getMessage()); //throw new CDIException(e.getMessage());
@ -191,15 +214,18 @@ public class Thread extends CObject implements ICDIThread {
} finally { } finally {
currentTarget.setCurrentThread(currentThread, false); currentTarget.setCurrentThread(currentThread, false);
} }
// take time to assign the currentFrame, if it is in the set
if (currentFrame == null) { if (currentFrame == null) {
for (int i = 0; i < stacks.length; i++) { for (int i = 0; i < currentFrames.size(); i++) {
StackFrame f = (StackFrame)stacks[i]; StackFrame f = (StackFrame) currentFrames.get(i);
if (f.getMIFrame().getLevel() == 0) { if (f.getMIFrame().getLevel() == 0) {
currentFrame = stacks[i]; currentFrame =f;
} }
} }
} }
return stacks; }
List list = currentFrames.subList(low, high);
return (ICDIStackFrame[])list.toArray(noStack);
} }
/** /**