提交 99fd4c42 编写于 作者: I isidor

debug: move getThreads to Process

上级 2c3225d9
...@@ -100,7 +100,8 @@ export interface ISession extends IBaseSession, ITreeElement { ...@@ -100,7 +100,8 @@ export interface ISession extends IBaseSession, ITreeElement {
} }
export interface IProcess extends IBaseSession, ITreeElement { export interface IProcess extends IBaseSession, ITreeElement {
getThread(threadId: number): IThread;
getAllThreads(): IThread[];
} }
export interface IThread extends ITreeElement { export interface IThread extends ITreeElement {
...@@ -223,7 +224,6 @@ export interface IViewModel extends ITreeElement { ...@@ -223,7 +224,6 @@ export interface IViewModel extends ITreeElement {
export interface IModel extends ITreeElement { export interface IModel extends ITreeElement {
getProcesses(): IProcess[]; getProcesses(): IProcess[];
getThreads(sessionId): { [threadId: number]: IThread; };
getBreakpoints(): IBreakpoint[]; getBreakpoints(): IBreakpoint[];
areBreakpointsActivated(): boolean; areBreakpointsActivated(): boolean;
getFunctionBreakpoints(): IFunctionBreakpoint[]; getFunctionBreakpoints(): IFunctionBreakpoint[];
......
...@@ -401,12 +401,20 @@ export class Thread implements debug.IThread { ...@@ -401,12 +401,20 @@ export class Thread implements debug.IThread {
export class Process implements debug.IProcess { export class Process implements debug.IProcess {
public threads: { [reference: number]: debug.IThread; }; private threads: { [reference: number]: debug.IThread; };
constructor(public session: debug.ISession) { constructor(public session: debug.ISession) {
this.threads = {}; this.threads = {};
} }
public getThread(threadId: number): debug.IThread {
return this.threads[threadId];
}
public getAllThreads(): debug.IThread[] {
return Object.keys(this.threads).map(key => this.threads[key]);
}
public getId(): string { public getId(): string {
return this.session.getId(); return this.session.getId();
} }
...@@ -621,15 +629,6 @@ export class Model implements debug.IModel { ...@@ -621,15 +629,6 @@ export class Model implements debug.IModel {
return this._onDidChangeREPLElements.event; return this._onDidChangeREPLElements.event;
} }
public getThreads(processId: string): { [reference: number]: debug.IThread; } {
const process = this.processes.filter(p => p.getId() === processId).pop();
if (!process) {
return {};
}
return process.threads;
}
public rawUpdate(data: debug.IRawModelUpdate): void { public rawUpdate(data: debug.IRawModelUpdate): void {
let process = this.processes.filter(p => p.getId() === data.rawSession.getId()).pop(); let process = this.processes.filter(p => p.getId() === data.rawSession.getId()).pop();
if (!process) { if (!process) {
......
...@@ -40,7 +40,7 @@ export class Source { ...@@ -40,7 +40,7 @@ export class Source {
// first try to find the raw source amongst the stack frames - since that represenation has more data (source reference), // first try to find the raw source amongst the stack frames - since that represenation has more data (source reference),
const processes = model.getProcesses(); const processes = model.getProcesses();
for (let i = 0; i < processes.length; i++) { for (let i = 0; i < processes.length; i++) {
const threads = model.getThreads(processes[i].getId()); const threads = process[i].getThreads();
for (let threadId in threads) { for (let threadId in threads) {
if (threads.hasOwnProperty(threadId) && threads[threadId].getCachedCallStack()) { if (threads.hasOwnProperty(threadId) && threads[threadId].getCachedCallStack()) {
const found = threads[threadId].getCachedCallStack().filter(sf => sf.source.uri.toString() === uri.toString()).pop(); const found = threads[threadId].getCachedCallStack().filter(sf => sf.source.uri.toString() === uri.toString()).pop();
......
...@@ -268,7 +268,8 @@ export class DebugService implements debug.IDebugService { ...@@ -268,7 +268,8 @@ export class DebugService implements debug.IDebugService {
allThreadsStopped: event.body.allThreadsStopped allThreadsStopped: event.body.allThreadsStopped
}); });
const thread = this.model.getThreads(session.getId())[threadId]; const process = this.model.getProcesses().filter(p => p.getId() === session.getId()).pop();
const thread = process.getThread(threadId);
thread.getCallStack().then(callStack => { thread.getCallStack().then(callStack => {
if (callStack.length > 0) { if (callStack.length > 0) {
// focus first stack frame from top that has source location // focus first stack frame from top that has source location
...@@ -981,9 +982,9 @@ export class DebugService implements debug.IDebugService { ...@@ -981,9 +982,9 @@ export class DebugService implements debug.IDebugService {
this.model.clearThreads(session.getId(), false, threadId); this.model.clearThreads(session.getId(), false, threadId);
// Get a top stack frame of a stopped thread if there is any. // Get a top stack frame of a stopped thread if there is any.
const threads = this.model.getThreads(session.getId());
const stoppedReference = Object.keys(threads).filter(ref => threads[ref].stopped).pop(); const process = this.model.getProcesses().filter(p => p.getId() === session.getId()).pop();
const stoppedThread = stoppedReference ? threads[parseInt(stoppedReference)] : null; const stoppedThread = process && process.getAllThreads().filter(t => t.stopped).pop();
const callStack = stoppedThread ? stoppedThread.getCachedCallStack() : null; const callStack = stoppedThread ? stoppedThread.getCachedCallStack() : null;
const stackFrameToFocus = callStack && callStack.length > 0 ? callStack[0] : null; const stackFrameToFocus = callStack && callStack.length > 0 ? callStack[0] : null;
......
...@@ -212,14 +212,14 @@ export class BaseDebugController extends treedefaults.DefaultController { ...@@ -212,14 +212,14 @@ export class BaseDebugController extends treedefaults.DefaultController {
// call stack // call stack
class ThreadAndSessionId { class ThreadAndProcessIds {
constructor(public sessionId: string, public threadId: number) { } constructor(public processId: string, public threadId: number) { }
} }
export class CallStackController extends BaseDebugController { export class CallStackController extends BaseDebugController {
protected onLeftClick(tree: tree.ITree, element: any, event: IMouseEvent): boolean { protected onLeftClick(tree: tree.ITree, element: any, event: IMouseEvent): boolean {
if (element instanceof ThreadAndSessionId) { if (element instanceof ThreadAndProcessIds) {
return this.showMoreStackFrames(tree, element); return this.showMoreStackFrames(tree, element);
} }
if (element instanceof model.StackFrame) { if (element instanceof model.StackFrame) {
...@@ -231,7 +231,7 @@ export class CallStackController extends BaseDebugController { ...@@ -231,7 +231,7 @@ export class CallStackController extends BaseDebugController {
protected onEnter(tree: tree.ITree, event: IKeyboardEvent): boolean { protected onEnter(tree: tree.ITree, event: IKeyboardEvent): boolean {
const element = tree.getFocus(); const element = tree.getFocus();
if (element instanceof ThreadAndSessionId) { if (element instanceof ThreadAndProcessIds) {
return this.showMoreStackFrames(tree, element); return this.showMoreStackFrames(tree, element);
} }
if (element instanceof model.StackFrame) { if (element instanceof model.StackFrame) {
...@@ -270,8 +270,9 @@ export class CallStackController extends BaseDebugController { ...@@ -270,8 +270,9 @@ export class CallStackController extends BaseDebugController {
} }
// user clicked / pressed on 'Load More Stack Frames', get those stack frames and refresh the tree. // user clicked / pressed on 'Load More Stack Frames', get those stack frames and refresh the tree.
private showMoreStackFrames(tree: tree.ITree, threadAndSessionId: ThreadAndSessionId): boolean { private showMoreStackFrames(tree: tree.ITree, threadAndProcessIds: ThreadAndProcessIds): boolean {
const thread = this.debugService.getModel().getThreads(threadAndSessionId.sessionId)[threadAndSessionId.threadId]; const process = this.debugService.getModel().getProcesses().filter(p => p.getId() === threadAndProcessIds.processId).pop();
const thread = process && process.getThread(threadAndProcessIds.threadId);
if (thread) { if (thread) {
thread.getCallStack(true) thread.getCallStack(true)
.done(() => tree.refresh(), errors.onUnexpectedError); .done(() => tree.refresh(), errors.onUnexpectedError);
...@@ -338,10 +339,6 @@ export class CallStackActionProvider implements renderer.IActionProvider { ...@@ -338,10 +339,6 @@ export class CallStackActionProvider implements renderer.IActionProvider {
export class CallStackDataSource implements tree.IDataSource { export class CallStackDataSource implements tree.IDataSource {
constructor( @debug.IDebugService private debugService: debug.IDebugService) {
// noop
}
public getId(tree: tree.ITree, element: any): string { public getId(tree: tree.ITree, element: any): string {
if (typeof element === 'number') { if (typeof element === 'number') {
return element.toString(); return element.toString();
...@@ -366,8 +363,7 @@ export class CallStackDataSource implements tree.IDataSource { ...@@ -366,8 +363,7 @@ export class CallStackDataSource implements tree.IDataSource {
} }
const process = <debug.IProcess>element; const process = <debug.IProcess>element;
const threads = this.debugService.getModel().getThreads(process.getId()); return TPromise.as(process.getAllThreads());
return TPromise.as(Object.keys(threads).map(ref => threads[ref]));
} }
private getThreadChildren(thread: debug.IThread): TPromise<any> { private getThreadChildren(thread: debug.IThread): TPromise<any> {
...@@ -376,7 +372,7 @@ export class CallStackDataSource implements tree.IDataSource { ...@@ -376,7 +372,7 @@ export class CallStackDataSource implements tree.IDataSource {
return callStack.concat([thread.stoppedDetails.framesErrorMessage]); return callStack.concat([thread.stoppedDetails.framesErrorMessage]);
} }
if (thread.stoppedDetails && thread.stoppedDetails.totalFrames > callStack.length) { if (thread.stoppedDetails && thread.stoppedDetails.totalFrames > callStack.length) {
return callStack.concat([new ThreadAndSessionId(thread.process.getId(), thread.threadId)]); return callStack.concat([new ThreadAndProcessIds(thread.process.getId(), thread.threadId)]);
} }
return callStack; return callStack;
......
...@@ -293,10 +293,9 @@ export class CallStackView extends viewlet.CollapsibleViewletView { ...@@ -293,10 +293,9 @@ export class CallStackView extends viewlet.CollapsibleViewletView {
let newTreeInput: any = this.debugService.getModel(); let newTreeInput: any = this.debugService.getModel();
const processes = this.debugService.getModel().getProcesses(); const processes = this.debugService.getModel().getProcesses();
if (processes.length === 1) { if (processes.length === 1) {
const threads = processes[0] ? model.getThreads(processes[0].getId()) : Object.create(null); const threads = processes[0].getAllThreads();
const threadsArray = Object.keys(threads).map(ref => threads[ref]);
// Only show the threads in the call stack if there is more than 1 thread. // Only show the threads in the call stack if there is more than 1 thread.
newTreeInput = threadsArray.length === 1 ? threadsArray[0] : processes[0]; newTreeInput = threads.length === 1 ? threads[0] : processes[0];
} }
if (this.tree.getInput() === newTreeInput) { if (this.tree.getInput() === newTreeInput) {
......
...@@ -12,13 +12,11 @@ import { MockSession } from 'vs/workbench/parts/debug/test/common/mockDebug'; ...@@ -12,13 +12,11 @@ import { MockSession } from 'vs/workbench/parts/debug/test/common/mockDebug';
suite('Debug - Model', () => { suite('Debug - Model', () => {
let model: debugmodel.Model; let model: debugmodel.Model;
let process: debugmodel.Process;
let rawSession: MockSession; let rawSession: MockSession;
setup(() => { setup(() => {
model = new debugmodel.Model([], true, [], [], []); model = new debugmodel.Model([], true, [], [], []);
rawSession = new MockSession(); rawSession = new MockSession();
process = new debugmodel.Process(rawSession);
}); });
teardown(() => { teardown(() => {
...@@ -91,12 +89,12 @@ suite('Debug - Model', () => { ...@@ -91,12 +89,12 @@ suite('Debug - Model', () => {
name: threadName name: threadName
} }
}); });
const process = model.getProcesses().filter(p => p.getId() === rawSession.getId()).pop();
var threads = model.getThreads(process.getId()); assert.equal(process.getThread(threadId).name, threadName);
assert.equal(threads[threadId].name, threadName);
model.clearThreads(process.getId(),true); model.clearThreads(process.getId(), true);
assert.equal(model.getThreads[threadId], null); assert.equal(process.getThread(threadId), null);
}); });
test('threads multiple wtih allThreadsStopped', () => { test('threads multiple wtih allThreadsStopped', () => {
...@@ -137,11 +135,13 @@ suite('Debug - Model', () => { ...@@ -137,11 +135,13 @@ suite('Debug - Model', () => {
}, },
allThreadsStopped: true allThreadsStopped: true
}); });
const process = model.getProcesses().filter(p => p.getId() === rawSession.getId()).pop();
const thread1 = model.getThreads(process.getId())[threadId1]; const thread1 = process.getThread(threadId1);
const thread2 = model.getThreads(process.getId())[threadId2]; const thread2 = process.getThread(threadId2);
// at the beginning, callstacks are obtainable but not available // at the beginning, callstacks are obtainable but not available
assert.equal(process.getAllThreads().length, 2);
assert.equal(thread1.name, threadName1); assert.equal(thread1.name, threadName1);
assert.equal(thread1.stopped, true); assert.equal(thread1.stopped, true);
assert.equal(thread1.getCachedCallStack(), undefined); assert.equal(thread1.getCachedCallStack(), undefined);
...@@ -183,8 +183,9 @@ suite('Debug - Model', () => { ...@@ -183,8 +183,9 @@ suite('Debug - Model', () => {
assert.equal(thread2.getCachedCallStack(), undefined); assert.equal(thread2.getCachedCallStack(), undefined);
model.clearThreads(process.getId(), true); model.clearThreads(process.getId(), true);
assert.equal(model.getThreads[threadId1], null); assert.equal(process.getThread(threadId1), null);
assert.equal(model.getThreads[threadId2], null); assert.equal(process.getThread(threadId2), null);
assert.equal(process.getAllThreads().length, 0);
}); });
test('threads mutltiple without allThreadsStopped', () => { test('threads mutltiple without allThreadsStopped', () => {
...@@ -225,14 +226,16 @@ suite('Debug - Model', () => { ...@@ -225,14 +226,16 @@ suite('Debug - Model', () => {
}, },
allThreadsStopped: false allThreadsStopped: false
}); });
const process = model.getProcesses().filter(p => p.getId() === rawSession.getId()).pop();
const stoppedThread = model.getThreads(process.getId())[stoppedThreadId]; const stoppedThread = process.getThread(stoppedThreadId);
const runningThread = model.getThreads(process.getId())[runningThreadId]; const runningThread = process.getThread(runningThreadId);
// the callstack for the stopped thread is obtainable but not available // the callstack for the stopped thread is obtainable but not available
// the callstack for the running thread is not obtainable nor available // the callstack for the running thread is not obtainable nor available
assert.equal(stoppedThread.name, stoppedThreadName); assert.equal(stoppedThread.name, stoppedThreadName);
assert.equal(stoppedThread.stopped, true); assert.equal(stoppedThread.stopped, true);
assert.equal(process.getAllThreads().length, 2);
assert.equal(stoppedThread.getCachedCallStack(), undefined); assert.equal(stoppedThread.getCachedCallStack(), undefined);
assert.equal(stoppedThread.stoppedDetails.reason, stoppedReason); assert.equal(stoppedThread.stoppedDetails.reason, stoppedReason);
assert.equal(runningThread.name, runningThreadName); assert.equal(runningThread.name, runningThreadName);
...@@ -268,8 +271,9 @@ suite('Debug - Model', () => { ...@@ -268,8 +271,9 @@ suite('Debug - Model', () => {
assert.equal(stoppedThread.getCachedCallStack(), undefined); assert.equal(stoppedThread.getCachedCallStack(), undefined);
model.clearThreads(process.getId(), true); model.clearThreads(process.getId(), true);
assert.equal(model.getThreads[stoppedThreadId], null); assert.equal(process.getThread(stoppedThreadId), null);
assert.equal(model.getThreads[runningThreadId], null); assert.equal(process.getThread(runningThreadId), null);
assert.equal(process.getAllThreads().length, 0 );
}); });
// Expressions // Expressions
...@@ -285,6 +289,7 @@ suite('Debug - Model', () => { ...@@ -285,6 +289,7 @@ suite('Debug - Model', () => {
test('watch expressions', () => { test('watch expressions', () => {
assert.equal(model.getWatchExpressions().length, 0); assert.equal(model.getWatchExpressions().length, 0);
const process = new debugmodel.Process(rawSession);
const thread = new debugmodel.Thread(process, 'mockthread', 1); const thread = new debugmodel.Thread(process, 'mockthread', 1);
const stackFrame = new debugmodel.StackFrame(thread, 1, null, 'app.js', 1, 1); const stackFrame = new debugmodel.StackFrame(thread, 1, null, 'app.js', 1, 1);
model.addWatchExpression(stackFrame, 'console').done(); model.addWatchExpression(stackFrame, 'console').done();
...@@ -305,6 +310,7 @@ suite('Debug - Model', () => { ...@@ -305,6 +310,7 @@ suite('Debug - Model', () => {
test('repl expressions', () => { test('repl expressions', () => {
assert.equal(model.getReplElements().length, 0); assert.equal(model.getReplElements().length, 0);
const process = new debugmodel.Process(rawSession);
const thread = new debugmodel.Thread(process, 'mockthread', 1); const thread = new debugmodel.Thread(process, 'mockthread', 1);
const stackFrame = new debugmodel.StackFrame(thread, 1, null, 'app.js', 1, 1); const stackFrame = new debugmodel.StackFrame(thread, 1, null, 'app.js', 1, 1);
model.addReplExpression(stackFrame, 'myVariable').done(); model.addReplExpression(stackFrame, 'myVariable').done();
...@@ -364,6 +370,7 @@ suite('Debug - Model', () => { ...@@ -364,6 +370,7 @@ suite('Debug - Model', () => {
assert.equal(debugmodel.getFullExpressionName(new debugmodel.Expression(null, false), type), null); assert.equal(debugmodel.getFullExpressionName(new debugmodel.Expression(null, false), type), null);
assert.equal(debugmodel.getFullExpressionName(new debugmodel.Expression('son', false), type), 'son'); assert.equal(debugmodel.getFullExpressionName(new debugmodel.Expression('son', false), type), 'son');
const process = new debugmodel.Process(rawSession);
const thread = new debugmodel.Thread(process, 'mockthread', 1); const thread = new debugmodel.Thread(process, 'mockthread', 1);
const stackFrame = new debugmodel.StackFrame(thread, 1, null, 'app.js', 1, 1); const stackFrame = new debugmodel.StackFrame(thread, 1, null, 'app.js', 1, 1);
const scope = new debugmodel.Scope(stackFrame, 'myscope', 1, false, 1, 0); const scope = new debugmodel.Scope(stackFrame, 'myscope', 1, false, 1, 0);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册