Skip to content

Commit fdbb98c

Browse files
committed
using line passed to debug hook for top of backtrace and falling back to function's linedefined if currentline is zero
1 parent 975a0f7 commit fdbb98c

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

debugger/debugger.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,27 @@ export namespace Debugger {
9797
return coroutine.running() ?? mainThread;
9898
}
9999

100+
function getLine(info: debug.FunctionInfo) {
101+
const currentLine = info.currentline && tonumber(info.currentline);
102+
if (currentLine && currentLine > 0) {
103+
return currentLine;
104+
}
105+
const lineDefined = info.linedefined && tonumber(info.linedefined);
106+
if (lineDefined && lineDefined > 0) {
107+
return lineDefined;
108+
}
109+
return -1;
110+
}
111+
100112
function backtrace(stack: debug.FunctionInfo[], frameIndex: number) {
101113
const frames: LuaDebug.Frame[] = [];
102114
for (const i of $range(0, stack.length - 1)) {
103115
const info = luaAssert(stack[i]);
104116
const frame: LuaDebug.Frame = {
105117
source: info.source && Path.format(info.source) || "?",
106-
line: info.currentline && luaAssert(tonumber(info.currentline)) || -1
118+
line: getLine(info)
107119
};
108-
if (info.source && info.currentline) {
120+
if (info.source) {
109121
const sourceMap = SourceMap.get(frame.source);
110122
if (sourceMap) {
111123
const lineMapping = sourceMap.mappings[frame.line];
@@ -446,9 +458,12 @@ export namespace Debugger {
446458
let updateHook: { (): void };
447459
let ignorePatterns: string[] | undefined;
448460

449-
function debugBreak(activeThread: Thread, stackOffset: number) {
461+
function debugBreak(activeThread: Thread, stackOffset: number, activeLine?: number) {
450462
++stackOffset;
451463
const activeStack = getStack(stackOffset);
464+
if (activeLine && activeStack.length > 0) {
465+
luaAssert(activeStack[0]).currentline = activeLine;
466+
}
452467
const activeThreadFrameOffset = stackOffset;
453468

454469
breakAtDepth = -1;
@@ -843,7 +858,7 @@ export namespace Debugger {
843858
}
844859

845860
Send.debugBreak("step", "step", getThreadId(activeThread));
846-
if (debugBreak(activeThread, debugHookStackOffset)) {
861+
if (debugBreak(activeThread, debugHookStackOffset, line)) {
847862
return;
848863
}
849864
}
@@ -882,7 +897,7 @@ export namespace Debugger {
882897
"breakpoint",
883898
getThreadId(activeThread)
884899
);
885-
debugBreak(activeThread, debugHookStackOffset);
900+
debugBreak(activeThread, debugHookStackOffset, line);
886901
break;
887902
}
888903
} else {
@@ -896,7 +911,7 @@ export namespace Debugger {
896911
"breakpoint",
897912
getThreadId(activeThread)
898913
);
899-
debugBreak(activeThread, debugHookStackOffset);
914+
debugBreak(activeThread, debugHookStackOffset, line);
900915
break;
901916
}
902917
}

0 commit comments

Comments
 (0)