MCPcopy Create free account
hub / github.com/Marus/cortex-debug / stackTraceRequest

Method stackTraceRequest

src/gdb.ts:2416–2484  ·  view source on GitHub ↗
(response: DebugProtocol.StackTraceResponse, args: DebugProtocol.StackTraceArguments)

Source from the content-addressed store, hash-verified

2414 }
2415
2416 protected stackTraceRequest(response: DebugProtocol.StackTraceResponse, args: DebugProtocol.StackTraceArguments): Promise<void> {
2417 response.body = {
2418 stackFrames: [],
2419 totalFrames: 0
2420 };
2421 // Handle optional args when not passed
2422 args.startFrame = args.startFrame ?? 0;
2423 args.levels = args.levels ?? Infinity;
2424 if (!this.isMIStatusStopped() || !this.stopped || this.disableSendStoppedEvents || this.continuing) {
2425 this.sendResponse(response);
2426 return Promise.resolve();
2427 }
2428 if (this.sendDummyStackTrace) {
2429 // VSCode has a bug. Once we send a Stopped Event, VSCode pause button refuses to work until some stack trace is
2430 // returned. We have issues during startup (and reset/restart) where we need to continue right after the initial
2431 // stop. So, we wait until VSCode got some dummy stack trace to continue. Not an issue if you have runToEntryPoint
2432 // but is an issue otherwise.
2433 // This also prevents disassembly getting requested while we are still in the middle of starting up and the PC can
2434 // temporarily be in la la land.
2435 if (this.args.showDevDebugOutput) {
2436 this.handleMsg('log', `Returning dummy stack frame to workaround VSCode issue with pause button not working: ${JSON.stringify(args)}\n`);
2437 }
2438 response.body.stackFrames = [new StackFrame(encodeReference(args.threadId, 0), 'cortex-debug-dummy', null, 0, 0)];
2439 response.body.totalFrames = 1;
2440 this.onInternalEvents.emit('stack-trace-request');
2441 this.sendResponse(response);
2442 return Promise.resolve();
2443 }
2444 return new Promise<void>(async (resolve) => {
2445 try {
2446 const maxDepth = await this.miDebugger.getStackDepth(args.threadId);
2447 const highFrame = Math.min(maxDepth, args.startFrame + args.levels) - 1;
2448 const stack = await this.miDebugger.getStack(args.threadId, args.startFrame, highFrame);
2449 const ret: StackFrame[] = [];
2450 for (const element of stack) {
2451 const stackId = encodeReference(args.threadId, element.level);
2452 const file = element.file;
2453 const src = file ? new Source(element.fileName, file) : undefined;
2454 const sf = new StackFrame(stackId, element.function + '@' + element.address, src, element.line, 0);
2455 sf.instructionPointerReference = element.address;
2456 ret.push(sf);
2457 }
2458
2459 if ((ret.length > 0) && !ret[0].source) {
2460 /*
2461 // Let VSCode stabilize on our stack information
2462 setTimeout(() => {
2463 this.sendEvent(new GenericCustomEvent('open-disassembly', {}));
2464 }, 10);
2465 */
2466 }
2467
2468 response.body = {
2469 stackFrames: ret,
2470 totalFrames: maxDepth
2471 };
2472 this.sendResponse(response);
2473 resolve();

Callers

nothing calls this directly

Calls 6

isMIStatusStoppedMethod · 0.95
handleMsgMethod · 0.95
encodeReferenceFunction · 0.85
getStackDepthMethod · 0.80
toStringMethod · 0.80
getStackMethod · 0.65

Tested by

no test coverage detected