[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [jdt-debug-dev] StackFrames and Variables
|
There's a class cast exception in your code, try this:
IStackFrame[] frames = (IStackFrame[]) thread.getStackFrames();
for(int i=0;i<frames.length;i++){
List variables =
((IJavaStackFrame)frames[i]).getArgumentTypeNames();
Iterator iter = variables.iterator();
while(iter.hasNext()){
System.out.println(iter.next().toString());}
}
Darin
Joe Tague <jtague@xxxxxxxxxxxxxxxx>
Sent by: jdt-debug-dev-admin@xxxxxxxxxxx
02/23/2005 10:09 AM
Please respond to
jdt-debug-dev
To
jdt-debug-dev@xxxxxxxxxxx
cc
Subject
Re: [jdt-debug-dev] StackFrames and Variables
Here is some example code, of what I am trying to achieve. I have
included how I set my markers and breakpoint to incase I am creating the
problem at these points.
Markers are set on a resource after some analysis of the AST for the
CompilationUnit:
public void candidatesFound(String classtype, final String method, final
String mode){
try{
type = project.findType(classtype);
} catch (JavaModelException e){..}
if (type == null) return; //TODO: Log Later
final IType finalType = type;
try{
final IResource resource = type.getResource();
IWorkspaceRunnable runnable = new IWorkspaceRunnable(){
public void run(IProgressMonitor monitor)throws CoreException{
IMarker marker =
resource.createMarker("org.eclipse.contribution.jimada.patternCandidate");
IMethod[] allMethods = finalType.getMethods();
IMethod candidateMethod = null;
for(int i=0;i<allMethods.length;i++){
if((allMethods[i].getElementName()).equals(method)){
candidateMethod = allMethods[i];
setMarkerAttributes(marker, candidateMethod, mode);
}
}
}
};
resource.getWorkspace().run(runnable, null);
} catch (CoreException e){..}
}
These markers and then used to create JavaMethodEntryBreakpoints for the
resource:
public BreakpointCreator(IJavaProject project, IMarker[] pattcandidates) {
javaProject = project;
candidates = pattcandidates;
}
public void create() {
for (int i = 0; i < candidates.length; i++) {
try {
if (candidates[i].getAttribute("METHOD") != null) {
IResource resource = candidates[i].getResource();
String type = candidates[i].getAttribute("TYPE", null);
String method = candidates[i].getAttribute("METHOD", null);
String signature = candidates[i].getAttribute("SIG", null);
int start = Integer.parseInt(candidates[i].getAttribute(
IMarker.CHAR_START, "-1"));
int end = Integer.parseInt(candidates[i].getAttribute(
IMarker.CHAR_END, "-1"));
int line = Integer.parseInt(candidates[i].getAttribute(
IMarker.LINE_NUMBER, "-1"));
if (type != null && method != null && signature != null){
IJavaMethodBreakpoint br =
JDIDebugModel.createMethodBreakpoint(resource,
type, method, signature, true, false, false,
line, start, end, 0,true,
candidates[i].getAttributes());}
}
} catch (NumberFormatException e) {..}
}
}
Now in my implementation of IJavaBreakpointListener I have the following
code, (methods not show are empty):
...
...
public int breakpointHit(IJavaThread thread, IJavaBreakpoint breakpoint) {
if(breakpoint instanceof IJavaMethodBreakpoint){
IJavaMethodBreakpoint br = (IJavaMethodBreakpoint)breakpoint;
mybreakpointHit(thread, br);
}
else if(breakpoint instanceof IJavaWatchpoint){
IJavaWatchpoint br = (IJavaWatchpoint)breakpoint;
mybreakpointHit(thread, br);
}
return IJavaBreakpointListener.DONT_SUSPEND;
}
private void mybreakpointHit(IJavaThread thread, IJavaMethodBreakpoint
breakpoint) {
// TODO Generate XML file from thread and breakpoint info.
try {
System.out.println(breakpoint.getMarker().getAttribute("METHOD").toString());
System.out.println(breakpoint.getMarker().getAttribute("SIG").toString());
System.out.println(breakpoint.getMarker().getAttribute(IMarker.LINE_NUMBER).toString());
IJavaStackFrame[] frames = (IJavaStackFrame[]) thread.getStackFrames();
for(int i=0;i<frames.length;i++){
List variables = frames[i].getArgumentTypeNames();
Iterator iter = variables.iterator();
while(iter.hasNext()){
System.out.println(iter.next().toString());}
}
}
Sorry for the long code listing. The problem happens at the start of the
IJavaStackFrame[] block. The first 3 lines, METHOD, SIG and LINE_NUMBER
will print to the console, but then in the run-time workbench the
perspective changes to Debug, and the first line of code in the method
the breakpoint is set at is highlighted and I have to click Resume to
step through the execution for each method a breakpoint is set at.
With out the IJavaStackFrame[] block the code performs as I expected it
to. The debugee is launch, the breakpoints are hit the debugee continues
as if they weren't there - i.e just like a normal run launch, and
information gets printed out to console.
Thanks so much for your patience and time.
Joe
Darin Wright wrote:
>>From the description provided, it sounds like you are doing the right
> thing to avoid suspending the thread.
>
> We have tests that demonstrate this behavior (see
> org.eclipse.jdt.debug.tests plugin - JavaBreakpointListenerTests). To be
> sure, I added a test for method breakpoints, and it all seems to be
> working. Perhaps you could provide us with a test case or small example
> that demonstrates the problem you are having (i.e. code that we can use
to
> replicate the problem)?
>
> Darin
>
>
<SNIPPED>
_______________________________________________
jdt-debug-dev mailing list
jdt-debug-dev@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/jdt-debug-dev