6 |
6 |
7 import java.util.List; |
7 import java.util.List; |
8 |
8 |
9 import org.chromium.debug.core.ChromiumDebugPlugin; |
9 import org.chromium.debug.core.ChromiumDebugPlugin; |
10 import org.chromium.sdk.CallFrame; |
10 import org.chromium.sdk.CallFrame; |
|
11 import org.chromium.sdk.DebugContext; |
11 import org.chromium.sdk.DebugContext.StepAction; |
12 import org.chromium.sdk.DebugContext.StepAction; |
12 import org.eclipse.core.runtime.IAdaptable; |
13 import org.eclipse.core.runtime.IAdaptable; |
|
14 import org.eclipse.core.runtime.IStatus; |
|
15 import org.eclipse.core.runtime.Status; |
13 import org.eclipse.debug.core.DebugEvent; |
16 import org.eclipse.debug.core.DebugEvent; |
14 import org.eclipse.debug.core.DebugException; |
17 import org.eclipse.debug.core.DebugException; |
15 import org.eclipse.debug.core.model.IBreakpoint; |
18 import org.eclipse.debug.core.model.IBreakpoint; |
16 import org.eclipse.debug.core.model.IStackFrame; |
19 import org.eclipse.debug.core.model.IStackFrame; |
17 import org.eclipse.debug.core.model.IThread; |
20 import org.eclipse.debug.core.model.IThread; |
18 import org.eclipse.osgi.util.NLS; |
|
19 |
21 |
20 /** |
22 /** |
21 * This class represents the only Chromium V8 VM thread. |
23 * This class represents the only Chromium V8 VM thread. |
22 */ |
24 */ |
23 public class JavascriptThread extends DebugElementImpl implements IThread, IAdaptable { |
25 public class JavascriptThread extends DebugElementImpl implements IThread, IAdaptable { |
44 /** |
46 /** |
45 * Constructs a new thread for the given target |
47 * Constructs a new thread for the given target |
46 * |
48 * |
47 * @param debugTarget this thread is created for |
49 * @param debugTarget this thread is created for |
48 */ |
50 */ |
49 public JavascriptThread(IChromiumDebugTarget debugTarget) { |
51 public JavascriptThread(DebugTargetImpl debugTarget) { |
50 super(debugTarget); |
52 super(debugTarget); |
51 } |
53 } |
52 |
54 |
53 public StackFrame[] getStackFrames() throws DebugException { |
55 public StackFrame[] getStackFrames() throws DebugException { |
54 if (isSuspended()) { |
56 ensureStackFrames(getDebugTarget().getDebugContext()); |
55 ensureStackFrames(); |
57 return stackFrames; |
56 return stackFrames; |
|
57 } else { |
|
58 return EMPTY_FRAMES; |
|
59 } |
|
60 } |
58 } |
61 |
59 |
62 public void reset() { |
60 public void reset() { |
63 this.stackFrames = null; |
61 this.stackFrames = null; |
64 } |
62 } |
65 |
63 |
66 private void ensureStackFrames() { |
64 private void ensureStackFrames(DebugContext debugContext) { |
67 this.stackFrames = wrapStackFrames(getDebugTarget().getDebugContext().getCallFrames()); |
65 if (debugContext == null) { |
|
66 this.stackFrames = EMPTY_FRAMES; |
|
67 } else { |
|
68 this.stackFrames = wrapStackFrames(debugContext.getCallFrames()); |
|
69 } |
68 } |
70 } |
69 |
71 |
70 private StackFrame[] wrapStackFrames(List<? extends CallFrame> jsFrames) { |
72 private StackFrame[] wrapStackFrames(List<? extends CallFrame> jsFrames) { |
71 StackFrame[] frames = new StackFrame[jsFrames.size()]; |
73 StackFrame[] frames = new StackFrame[jsFrames.size()]; |
72 for (int i = 0, size = frames.length; i < size; ++i) { |
74 for (int i = 0, size = frames.length; i < size; ++i) { |
90 } |
92 } |
91 return null; |
93 return null; |
92 } |
94 } |
93 |
95 |
94 public String getName() throws DebugException { |
96 public String getName() throws DebugException { |
95 String url = getDebugTarget().getJavascriptEmbedder().getThreadName(); |
97 return getDebugTarget().getLabelProvider().getThreadLabel(this); |
96 return NLS.bind(Messages.JsThread_ThreadLabelFormat, (isSuspended() |
|
97 ? Messages.JsThread_ThreadLabelSuspended |
|
98 : Messages.JsThread_ThreadLabelRunning), (url.length() > 0 |
|
99 ? (" : " + url) : "")); //$NON-NLS-1$ //$NON-NLS-2$ |
|
100 } |
98 } |
101 |
99 |
102 public IBreakpoint[] getBreakpoints() { |
100 public IBreakpoint[] getBreakpoints() { |
103 if (breakpoints == null) { |
101 if (breakpoints == null) { |
104 return new IBreakpoint[0]; |
102 return new IBreakpoint[0]; |
146 public boolean isStepping() { |
144 public boolean isStepping() { |
147 return isStepping; |
145 return isStepping; |
148 } |
146 } |
149 |
147 |
150 private void step(StepAction stepAction, int detail) throws DebugException { |
148 private void step(StepAction stepAction, int detail) throws DebugException { |
|
149 DebugContext debugContext = getDebugTarget().getDebugContext(); |
|
150 if (debugContext == null) { |
|
151 throw new DebugException(new Status(IStatus.ERROR, ChromiumDebugPlugin.PLUGIN_ID, |
|
152 "Step attempted while not suspended")); //$NON-NLS-1$ |
|
153 } |
151 setStepping(true); |
154 setStepping(true); |
152 getDebugTarget().getDebugContext().continueVm(stepAction, 1, null); |
155 debugContext.continueVm(stepAction, 1, null); |
153 // The suspend event should be fired once the backtrace is ready |
156 // The suspend event should be fired once the backtrace is ready |
154 // (in BacktraceProcessor). |
157 // (in BacktraceProcessor). |
155 getDebugTarget().fireResumeEvent(detail); |
158 getDebugTarget().fireResumeEvent(detail); |
156 } |
159 } |
157 |
160 |
187 } |
190 } |
188 |
191 |
189 @Override |
192 @Override |
190 @SuppressWarnings("unchecked") |
193 @SuppressWarnings("unchecked") |
191 public Object getAdapter(Class adapter) { |
194 public Object getAdapter(Class adapter) { |
192 if (adapter == StackFrame.class) { |
195 if (adapter == EvaluateContext.class) { |
193 try { |
196 DebugContext debugContext = getDebugTarget().getDebugContext(); |
194 return getTopStackFrame(); |
197 if (debugContext == null) { |
195 } catch (DebugException e) { |
198 return null; |
196 ChromiumDebugPlugin.log(e); |
|
197 } |
199 } |
|
200 return new EvaluateContext(debugContext.getGlobalEvaluateContext(), getDebugTarget()); |
198 } |
201 } |
199 return super.getAdapter(adapter); |
202 return super.getAdapter(adapter); |
200 } |
203 } |
201 } |
204 } |