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,26 +81,29 @@ 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
Session session = (Session)getTarget().getSession(); int depth = getStackFrameCount();
Target currentTarget = (Target)session.getCurrentTarget();
// 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();
Target currentTarget = (Target) session.getCurrentTarget();
ICDIThread currentThread = currentTarget.getCurrentThread(); ICDIThread currentThread = currentTarget.getCurrentThread();
currentTarget.setCurrentThread(this, false); currentTarget.setCurrentThread(this, false);
try { try {
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);
} }
/** /**
@ -119,8 +132,8 @@ public class Thread extends CObject implements ICDIThread {
*/ */
public int getStackFrameCount() throws CDIException { public int getStackFrameCount() throws CDIException {
if (stackdepth == 0) { if (stackdepth == 0) {
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 {
@ -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) {
Session session = (Session)getTarget().getSession(); currentFrames = new ArrayList();
Target currentTarget = (Target)session.getCurrentTarget(); Session session = (Session) getTarget().getSession();
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);
} }
/** /**
@ -226,7 +252,7 @@ public class Thread extends CObject implements ICDIThread {
} }
try { try {
Session session = (Session)getTarget().getSession(); Session session = (Session) getTarget().getSession();
MISession mi = session.getMISession(); MISession mi = session.getMISession();
CommandFactory factory = mi.getCommandFactory(); CommandFactory factory = mi.getCommandFactory();
// Need the GDB/MI view of level which is the reverse, i.e. the highest level is 0 // Need the GDB/MI view of level which is the reverse, i.e. the highest level is 0
@ -234,7 +260,7 @@ public class Thread extends CObject implements ICDIThread {
int miLevel = getStackFrameCount() - frameLevel; int miLevel = getStackFrameCount() - frameLevel;
MIStackSelectFrame frame = factory.createMIStackSelectFrame(miLevel); MIStackSelectFrame frame = factory.createMIStackSelectFrame(miLevel);
// Set ourself as the current thread first. // Set ourself as the current thread first.
((Target)getTarget()).setCurrentThread(this, doUpdate); ((Target) getTarget()).setCurrentThread(this, doUpdate);
mi.postCommand(frame); mi.postCommand(frame);
MIInfo info = frame.getMIInfo(); MIInfo info = frame.getMIInfo();
if (info == null) { if (info == null) {
@ -245,11 +271,11 @@ public class Thread extends CObject implements ICDIThread {
// some variables like registers. Call an update() // some variables like registers. Call an update()
// To generate changeEvents. // To generate changeEvents.
if (doUpdate) { if (doUpdate) {
RegisterManager regMgr = (RegisterManager)session.getRegisterManager(); RegisterManager regMgr = (RegisterManager) session.getRegisterManager();
if (regMgr.isAutoUpdate()) { if (regMgr.isAutoUpdate()) {
regMgr.update(); regMgr.update();
} }
VariableManager varMgr = (VariableManager)session.getVariableManager(); VariableManager varMgr = (VariableManager) session.getVariableManager();
if (varMgr.isAutoUpdate()) { if (varMgr.isAutoUpdate()) {
varMgr.update(); varMgr.update();
} }