@@ -97,15 +97,27 @@ export namespace Debugger {
97
97
return coroutine . running ( ) ?? mainThread ;
98
98
}
99
99
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
+
100
112
function backtrace ( stack : debug . FunctionInfo [ ] , frameIndex : number ) {
101
113
const frames : LuaDebug . Frame [ ] = [ ] ;
102
114
for ( const i of $range ( 0 , stack . length - 1 ) ) {
103
115
const info = luaAssert ( stack [ i ] ) ;
104
116
const frame : LuaDebug . Frame = {
105
117
source : info . source && Path . format ( info . source ) || "?" ,
106
- line : info . currentline && luaAssert ( tonumber ( info . currentline ) ) || - 1
118
+ line : getLine ( info )
107
119
} ;
108
- if ( info . source && info . currentline ) {
120
+ if ( info . source ) {
109
121
const sourceMap = SourceMap . get ( frame . source ) ;
110
122
if ( sourceMap ) {
111
123
const lineMapping = sourceMap . mappings [ frame . line ] ;
@@ -446,9 +458,12 @@ export namespace Debugger {
446
458
let updateHook : { ( ) : void } ;
447
459
let ignorePatterns : string [ ] | undefined ;
448
460
449
- function debugBreak ( activeThread : Thread , stackOffset : number ) {
461
+ function debugBreak ( activeThread : Thread , stackOffset : number , activeLine ?: number ) {
450
462
++ stackOffset ;
451
463
const activeStack = getStack ( stackOffset ) ;
464
+ if ( activeLine && activeStack . length > 0 ) {
465
+ luaAssert ( activeStack [ 0 ] ) . currentline = activeLine ;
466
+ }
452
467
const activeThreadFrameOffset = stackOffset ;
453
468
454
469
breakAtDepth = - 1 ;
@@ -843,7 +858,7 @@ export namespace Debugger {
843
858
}
844
859
845
860
Send . debugBreak ( "step" , "step" , getThreadId ( activeThread ) ) ;
846
- if ( debugBreak ( activeThread , debugHookStackOffset ) ) {
861
+ if ( debugBreak ( activeThread , debugHookStackOffset , line ) ) {
847
862
return ;
848
863
}
849
864
}
@@ -882,7 +897,7 @@ export namespace Debugger {
882
897
"breakpoint" ,
883
898
getThreadId ( activeThread )
884
899
) ;
885
- debugBreak ( activeThread , debugHookStackOffset ) ;
900
+ debugBreak ( activeThread , debugHookStackOffset , line ) ;
886
901
break ;
887
902
}
888
903
} else {
@@ -896,7 +911,7 @@ export namespace Debugger {
896
911
"breakpoint" ,
897
912
getThreadId ( activeThread )
898
913
) ;
899
- debugBreak ( activeThread , debugHookStackOffset ) ;
914
+ debugBreak ( activeThread , debugHookStackOffset , line ) ;
900
915
break ;
901
916
}
902
917
}
0 commit comments