mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-06 09:16:02 +02:00
Cache the stackframes to reduce the chatting between
GDB.
This commit is contained in:
parent
e35bc93925
commit
74d7916ebc
2 changed files with 112 additions and 79 deletions
|
@ -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.
|
||||||
|
|
||||||
|
|
|
@ -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,13 +36,16 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getId() {
|
public int getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
@ -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,44 +81,50 @@ 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();
|
|
||||||
ICDIThread currentThread = currentTarget.getCurrentThread();
|
// refresh if we have nothing or if we have just a subset get everything.
|
||||||
currentTarget.setCurrentThread(this, false);
|
if (currentFrames == null || currentFrames.size() < depth) {
|
||||||
try {
|
currentFrames = new ArrayList();
|
||||||
MISession mi = session.getMISession();
|
Session session = (Session) getTarget().getSession();
|
||||||
CommandFactory factory = mi.getCommandFactory();
|
Target currentTarget = (Target) session.getCurrentTarget();
|
||||||
MIStackListFrames frames = factory.createMIStackListFrames();
|
ICDIThread currentThread = currentTarget.getCurrentThread();
|
||||||
depth = getStackFrameCount();
|
currentTarget.setCurrentThread(this, false);
|
||||||
mi.postCommand(frames);
|
try {
|
||||||
MIStackListFramesInfo info = frames.getMIStackListFramesInfo();
|
MISession mi = session.getMISession();
|
||||||
if (info == null) {
|
CommandFactory factory = mi.getCommandFactory();
|
||||||
throw new CDIException("No answer");
|
MIStackListFrames frames = factory.createMIStackListFrames();
|
||||||
|
mi.postCommand(frames);
|
||||||
|
MIStackListFramesInfo info = frames.getMIStackListFramesInfo();
|
||||||
|
if (info == null) {
|
||||||
|
throw new CDIException("No answer");
|
||||||
|
}
|
||||||
|
MIFrame[] miFrames = info.getMIFrames();
|
||||||
|
for (int i = 0; i < miFrames.length; i++) {
|
||||||
|
currentFrames.add(new StackFrame(this, miFrames[i], depth - miFrames[i].getLevel()));
|
||||||
|
}
|
||||||
|
} catch (MIException e) {
|
||||||
|
//throw new CDIException(e.getMessage());
|
||||||
|
//System.out.println(e);
|
||||||
|
} catch (CDIException e) {
|
||||||
|
//throw e;
|
||||||
|
//System.out.println(e);
|
||||||
|
} finally {
|
||||||
|
currentTarget.setCurrentThread(currentThread, false);
|
||||||
}
|
}
|
||||||
MIFrame[] miFrames = info.getMIFrames();
|
// assign the currentFrame if it was not done yet.
|
||||||
stacks = new StackFrame[miFrames.length];
|
if (currentFrame == null) {
|
||||||
for (int i = 0; i < stacks.length; i++) {
|
for (int i = 0; i < currentFrames.size(); i++) {
|
||||||
stacks[i] = new StackFrame(this, miFrames[i], depth - miFrames[i].getLevel());
|
ICDIStackFrame stack = (ICDIStackFrame) currentFrames.get(i);
|
||||||
}
|
if (stack.getLevel() == depth) {
|
||||||
} catch (MIException e) {
|
currentFrame = stack;
|
||||||
//throw new CDIException(e.getMessage());
|
}
|
||||||
//System.out.println(e);
|
|
||||||
} catch (CDIException e) {
|
|
||||||
//throw e;
|
|
||||||
//System.out.println(e);
|
|
||||||
} finally {
|
|
||||||
currentTarget.setCurrentThread(currentThread, false);
|
|
||||||
}
|
|
||||||
if (currentFrame == null) {
|
|
||||||
for (int i = 0; i < stacks.length; i++) {
|
|
||||||
if (stacks[i].getLevel() == depth) {
|
|
||||||
currentFrame = stacks[i];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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,44 +175,57 @@ 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();
|
||||||
ICDIThread currentThread = currentTarget.getCurrentThread();
|
Target currentTarget = (Target) session.getCurrentTarget();
|
||||||
currentTarget.setCurrentThread(this, false);
|
ICDIThread currentThread = currentTarget.getCurrentThread();
|
||||||
try {
|
currentTarget.setCurrentThread(this, false);
|
||||||
MISession mi = session.getMISession();
|
try {
|
||||||
CommandFactory factory = mi.getCommandFactory();
|
int depth = getStackFrameCount();
|
||||||
MIStackListFrames frames = factory.createMIStackListFrames(low, high);
|
int upperBound;
|
||||||
int depth = getStackFrameCount();
|
// try to get the largest subset.
|
||||||
mi.postCommand(frames);
|
// if what the user asks is smaller then the depth
|
||||||
MIStackListFramesInfo info = frames.getMIStackListFramesInfo();
|
// try to cache things by getting the min(depth,STACKFRAME_DEFAULT_DEPTH)
|
||||||
if (info == null) {
|
// else give fetch the entire thing.
|
||||||
throw new CDIException("No answer");
|
if (high < depth) {
|
||||||
|
upperBound = Math.min(depth, STACKFRAME_DEFAULT_DEPTH);
|
||||||
|
} else {
|
||||||
|
upperBound = depth;
|
||||||
|
}
|
||||||
|
MISession mi = session.getMISession();
|
||||||
|
CommandFactory factory = mi.getCommandFactory();
|
||||||
|
MIStackListFrames frames = factory.createMIStackListFrames(0, upperBound);
|
||||||
|
mi.postCommand(frames);
|
||||||
|
MIStackListFramesInfo info = frames.getMIStackListFramesInfo();
|
||||||
|
if (info == null) {
|
||||||
|
throw new CDIException("No answer");
|
||||||
|
}
|
||||||
|
MIFrame[] miFrames = info.getMIFrames();
|
||||||
|
for (int i = 0; i < miFrames.length; i++) {
|
||||||
|
currentFrames.add(new StackFrame(this, miFrames[i], depth - miFrames[i].getLevel()));
|
||||||
|
}
|
||||||
|
} catch (MIException e) {
|
||||||
|
//throw new CDIException(e.getMessage());
|
||||||
|
//System.out.println(e);
|
||||||
|
} catch (CDIException e) {
|
||||||
|
//throw e;
|
||||||
|
//System.out.println(e);
|
||||||
|
} finally {
|
||||||
|
currentTarget.setCurrentThread(currentThread, false);
|
||||||
}
|
}
|
||||||
MIFrame[] miFrames = info.getMIFrames();
|
// take time to assign the currentFrame, if it is in the set
|
||||||
stacks = new StackFrame[miFrames.length];
|
if (currentFrame == null) {
|
||||||
for (int i = 0; i < stacks.length; i++) {
|
for (int i = 0; i < currentFrames.size(); i++) {
|
||||||
stacks[i] = new StackFrame(this, miFrames[i], depth - miFrames[i].getLevel());
|
StackFrame f = (StackFrame) currentFrames.get(i);
|
||||||
}
|
if (f.getMIFrame().getLevel() == 0) {
|
||||||
} catch (MIException e) {
|
currentFrame =f;
|
||||||
//throw new CDIException(e.getMessage());
|
}
|
||||||
//System.out.println(e);
|
|
||||||
} catch (CDIException e) {
|
|
||||||
//throw e;
|
|
||||||
//System.out.println(e);
|
|
||||||
} finally {
|
|
||||||
currentTarget.setCurrentThread(currentThread, false);
|
|
||||||
}
|
|
||||||
if (currentFrame == null) {
|
|
||||||
for (int i = 0; i < stacks.length; i++) {
|
|
||||||
StackFrame f = (StackFrame)stacks[i];
|
|
||||||
if (f.getMIFrame().getLevel() == 0) {
|
|
||||||
currentFrame = stacks[i];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return stacks;
|
List list = currentFrames.subList(low, high);
|
||||||
|
return (ICDIStackFrame[])list.toArray(noStack);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -217,7 +243,7 @@ public class Thread extends CObject implements ICDIThread {
|
||||||
if (stackframe != null) {
|
if (stackframe != null) {
|
||||||
frameLevel = stackframe.getLevel();
|
frameLevel = stackframe.getLevel();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check to see if we are already at this level
|
// Check to see if we are already at this level
|
||||||
ICDIStackFrame current = getCurrentStackFrame();
|
ICDIStackFrame current = getCurrentStackFrame();
|
||||||
if (current != null && current.getLevel() == frameLevel) {
|
if (current != null && current.getLevel() == frameLevel) {
|
||||||
|
@ -226,15 +252,15 @@ 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
|
||||||
// See comment in StackFrame constructor.
|
// See comment in StackFrame constructor.
|
||||||
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) {
|
||||||
|
@ -242,14 +268,14 @@ public class Thread extends CObject implements ICDIThread {
|
||||||
}
|
}
|
||||||
currentFrame = stackframe;
|
currentFrame = stackframe;
|
||||||
// Resetting stackframe may change the value of
|
// Resetting stackframe may change the value of
|
||||||
// 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();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue