actboy168 / lua-debug

Lua Debug Adapter for Visual Studio Code
MIT License
431 stars 93 forks source link

attach 调试问题 #205

Closed zhongfq closed 1 year ago

zhongfq commented 1 year ago

QQ截图20221206203533 QQ截图20221206203550

配置: { "name": "launh process", "type": "lua", "request": "launch", "stopOnEntry":true, "runtimeExecutable": "${workspaceFolder}/build/vs-build/bin/hihikid/Debug/hihikid.exe", "cwd":"${workspaceFolder}/assets/", "sourceMaps": [ [ "./assets/", "${workspaceFolder}/" ] ], "runtimeArgs":["-p", "--listen=12306"] }

可以启动,但断点无法生效,不知道哪里出问题

zhongfq commented 1 year ago

断点提示:Wait verify. (The source file is not loaded.)

actboy168 commented 1 year ago

打开侧边栏里的已载入的脚本,看看你的代码是否已经被加载,以及加载的路径是什么

zhongfq commented 1 year ago

QQ截图20221207102719 我已经设置了sourceMap了,但是加载的路径还是不对

actboy168 commented 1 year ago

sourceMaps 每一项需要两个值,声明chunkname如何映射到真正的脚本文件。

"sourceMaps": [
  [
    "./app/build/vs-build/*",
    "${workspaceFolder}/assets/*"
  ]
]
zhongfq commented 1 year ago

QQ截图20221207102719 还是同样的问题

actboy168 commented 1 year ago

我只是举个例子,具体sourceMaps要怎么写得根据你的chunkname来决定。如果已加载脚本里的路径没有变成你想要的路径,就说明没写对。

zhongfq commented 1 year ago

QQ截图20221207102719 这个路径是想要的了,但是,还是那个问题

actboy168 commented 1 year ago

1.找到插件的目录,应该是在%UserProfile%/.vscode/extensions/actboy168.lua-debug-1.60.1-win32-x64。 2.打开script/frontend/main.lua,把里面的一行注释打开。 3.再运行一次。 4.在插件目录找到日志文件client.log,发给我看看。

zhongfq commented 1 year ago

[2022-12-07 13:14:33:010][common/protocol.lua: 37][INFO ][recv] {"command":"initialize","arguments":{"clientID":"vscode","clientName":"Visual Studio Code","adapterID":"lua","pathFormat":"path","linesStartAt1":true,"columnsStartAt1":true,"supportsVariableType":true,"supportsVariablePaging":true,"supportsRunInTerminalRequest":true,"locale":"zh-cn","supportsProgressReporting":true,"supportsInvalidatedEvent":true,"supportsMemoryReferences":true,"supportsArgsCanBeInterpretedByShell":true},"type":"request","seq":1} [2022-12-07 13:14:33:013][common/protocol.lua: 47][INFO ][send] {"body":{"exceptionBreakpointFilters":[{"default":false,"description":"Error raised by lua runtime.","filter":"runtime","label":"Runtime Errors","supportsCondition":true},{"default":false,"description":"Error raised by assert.","filter":"assert","label":"Assertion Errors","supportsCondition":true},{"default":false,"description":"Error raised by error.","filter":"error","label":"Common Errors","supportsCondition":true},{"default":false,"description":"Syntax error.","filter":"syntax","label":"Syntax Errors","supportsCondition":true},{"default":false,"description":"Error raised by lua_error.","filter":"other","label":"Native Errors","supportsCondition":true},{"conditionDescription":"error:match \"attempt to index a nil value\"","default":false,"description":"Breaks on errors, if it is caught by lua.","filter":"lua","label":"Caught Errors By Lua","supportsCondition":true},{"conditionDescription":"error:match \"attempt to index a nil value\"","default":true,"description":"Breaks on errors, if it is caught by native code.","filter":"native","label":"Caught Errors By Native","supportsCondition":true},{"conditionDescription":"error:match \"attempt to index a nil value\"","default":true,"description":"Breaks only on errors that are nor handled.","filter":"panic","label":"Uncaught Errors","supportsCondition":true}],"supportSuspendDebuggee":true,"supportTerminateDebuggee":true,"supportsClipboardContext":true,"supportsConditionalBreakpoints":true,"supportsConfigurationDoneRequest":true,"supportsDelayedStackTraceLoading":true,"supportsEvaluateForHovers":true,"supportsExceptionFilterOptions":true,"supportsExceptionInfoRequest":true,"supportsFunctionBreakpoints":true,"supportsHitConditionalBreakpoints":true,"supportsLoadedSourcesRequest":true,"supportsLogPoints":true,"supportsReadMemoryRequest":true,"supportsRestartFrame":true,"supportsRestartRequest":true,"supportsSetExpression":true,"supportsSetVariable":true,"supportsTerminateRequest":true,"supportsTerminateThreadsRequest":true,"supportsWriteMemoryRequest":true},"command":"initialize","request_seq":1,"seq":0,"success":true,"type":"response"} [2022-12-07 13:14:33:042][common/protocol.lua: 37][INFO ][recv] {"command":"attach","arguments":{"address":"127.0.0.1:12306","name":"attach","request":"attach","stopOnEntry":true,"type":"lua","sourceMaps":[["","D:\User\Desktop\hihikid\app/assets/"]],"__configurationTarget":6,"workspaceFolder":"d:\User\Desktop\hihikid\app","cwd":"d:\User\Desktop\hihikid\app","stopOnThreadEntry":false,"luaVersion":"5.4","luaArch":"x86_64","console":"integratedTerminal","sourceCoding":"utf8","outputCapture":[],"pathFormat":"path","client":true,"configuration":{"variables":{"showIntegerAsHex":false}},"__sessionId":"2d264acf-2db9-4a7a-8cc8-1b70f8850497"},"type":"request","seq":2} [2022-12-07 13:14:51:940][common/protocol.lua: 47][INFO ][send] {"event":"initialized","seq":2,"type":"event"} [2022-12-07 13:14:51:940][common/protocol.lua: 47][INFO ][send] {"body":{"capabilities":{"exceptionBreakpointFilters":[{"default":false,"description":"Error raised by lua runtime.","filter":"runtime","label":"Runtime Errors","supportsCondition":true},{"default":false,"description":"Error raised by assert.","filter":"assert","label":"Assertion Errors","supportsCondition":true},{"default":false,"description":"Error raised by error.","filter":"error","label":"Common Errors","supportsCondition":true},{"default":false,"description":"Syntax error.","filter":"syntax","label":"Syntax Errors","supportsCondition":true},{"default":false,"description":"Error raised by lua_error.","filter":"other","label":"Native Errors","supportsCondition":true},{"conditionDescription":"error:match \"attempt to index a nil value\"","default":false,"description":"Breaks on errors, if it is caught by lua.","filter":"lua","label":"Caught Errors By Lua","supportsCondition":true},{"conditionDescription":"error:match \"attempt to index a nil value\"","default":true,"description":"Breaks on errors, if it is caught by native code.","filter":"native","label":"Caught Errors By Native","supportsCondition":true},{"conditionDescription":"error:match \"attempt to index a nil value\"","default":true,"description":"Breaks only on errors that are nor handled.","filter":"panic","label":"Uncaught Errors","supportsCondition":true}],"supportSuspendDebuggee":true,"supportTerminateDebuggee":true,"supportsClipboardContext":true,"supportsConditionalBreakpoints":true,"supportsConfigurationDoneRequest":true,"supportsDelayedStackTraceLoading":true,"supportsEvaluateForHovers":true,"supportsExceptionFilterOptions":true,"supportsExceptionInfoRequest":true,"supportsFunctionBreakpoints":true,"supportsHitConditionalBreakpoints":true,"supportsLoadedSourcesRequest":true,"supportsLogPoints":true,"supportsReadMemoryRequest":true,"supportsRestartFrame":true,"supportsRestartRequest":true,"supportsSetExpression":true,"supportsSetVariable":true,"supportsTerminateRequest":true,"supportsTerminateThreadsRequest":true,"supportsWriteMemoryRequest":true}},"event":"capabilities","seq":3,"type":"event"} [2022-12-07 13:14:51:950][common/protocol.lua: 47][INFO ][send] {"command":"attach","request_seq":2,"seq":4,"success":true,"type":"response"} [2022-12-07 13:14:51:981][common/protocol.lua: 37][INFO ][recv] {"command":"setBreakpoints","arguments":{"source":{"name":"init.lua","path":"d:\User\Desktop\hihikid\app\assets\src\init.lua"},"lines":[53],"breakpoints":[{"line":53}],"sourceModified":false,"sourceContent":"require \"misc.sdk\" -- init sdk\n\nlocal window = require \"cclua.window\"\nlocal runtime = require \"cclua.runtime\"\nlocal swf = require \"cclua.swf.swf\"\nlocal font = require \"cclua.font\"\nlocal timer = require \"cclua.timer\"\nlocal filesystem = require \"cclua.filesystem\"\nlocal downloader = require \"cclua.downloader\"\nlocal UIConfig = require \"fgui.UIConfig\"\nlocal conf = require \"misc.conf\"\n\n-- test gc\n-- local timer = require \"cclua.timer\"\n-- timer.schedule(2, function ()\n-- runtime.gc()\n-- end)\n\n-- set window size on mac\nif runtime.os == 'mac' then\n window.setFrameSize(800, 500)\n DEBUG = true\nelseif runtime.os == 'win32' then\n window.setFrameSize(1200, 750)\n DEBUG = true\nend\n\nif runtime.packageName == 'com.hihikid.park' then\n DEBUG = true\n runtime.setEnv('cclua.debug', 'true', true)\nend\n\n-- olua.debug(DEBUG)\n\n-- enable lua debug\nif DEBUG then\n require \"debugger\":start \"127.0.0.1:12306\":event \"wait\"\n -- require(\"LuaPanda\").start(\"127.0.0.1\", 8818)\n -- local hanlder = require(\"cclua.LuaDebug\")(\"localhost\", 7003)\n -- timer.schedule(0, hanlder)\nend\n\n-- remove cache file\nfilesystem.remove(filesystem.dir.cache .. '/http')\n\n-- print runtime info\nif DEBUG then\n runtime.disableReport()\nend\n\n-- set status & frame rate\nruntime.frameRate = 60\nruntime.displayStats = DEBUG\n\n-- init design size\ndo\n local ResolutionPolicy = require \"cc.ResolutionPolicy\"\n local width, height = window:getFrameSize()\n -- local DESIGN_WIDTH = 1625\n local DESIGN_HEIGHT = 750\n local DESIGN_WIDTH = width / height * DESIGN_HEIGHT\n window.setDesignSize(DESIGN_WIDTH, DESIGN_HEIGHT, ResolutionPolicy.NO_BORDER)\n printf('window size: %.fx%.f', width, height)\n printf('design size: %.fx%.f', DESIGN_WIDTH, DESIGNHEIGHT)\nend\n\n-- translate uri\ndownloader.setURIResolver(function (uri)\n if string.find(uri, '^uri://') then\n uri = string.gsub(uri, '^uri:/', conf.SERVER)\n end\n return uri\nend)\n\n-- ios audio session\nruntime.audioSessionCatalog = 'AVAudioSessionCategoryPlayback'\n\n-- font\nlocal fonts = {\n {name = \"思源黑体 CN\", path = 'res/font/sourcehansans.ttf', ascent = 23753},\n {name = \"思源黑体 CN Medium\", path = 'res/font/sourcehansans-medium.ttf', ascent = 23753},\n {name = \"思源黑体 CN Bold\", path = 'res/font/sourcehansans-bold.ttf', ascent = 23753},\n {name = \"楷体\", path = 'res/font/simkai.ttf', ascent = 18000},\n}\nfor , v in ipairs(fonts) do\n font.register(v)\n swf.registerFont(v)\n UIConfig.registerFont(v.name, v.path)\nend\nUIConfig.defaultFont = '思源黑体 CN'\n\n-- swf\nswf.setForceRealtimeFrameRate(true)\ndo\n local width, height = window:getFrameSize()\n if width / height < 1250 / 750 then\n -- 在iPad上,让矢量分解更细致\n swf.setCurveMaxPixelError(0.5)\n end\nend\n"},"type":"request","seq":3} [2022-12-07 13:14:51:981][common/protocol.lua: 37][INFO ][recv] {"command":"setFunctionBreakpoints","arguments":{"breakpoints":[]},"type":"request","seq":4} [2022-12-07 13:14:51:983][common/protocol.lua: 37][INFO ][recv] {"command":"setExceptionBreakpoints","arguments":{"filters":[],"filterOptions":[{"filterId":"native"},{"filterId":"panic"}]},"type":"request","seq":5} [2022-12-07 13:14:52:044][common/protocol.lua: 37][INFO ][recv] {"command":"loadedSources","type":"request","seq":6} [2022-12-07 13:14:52:046][common/protocol.lua: 47][INFO ][send] {"body":{"breakpoints":[{"id":1,"line":53,"message":"Wait verify. (The source file is not loaded.)","verified":false}]},"command":"setBreakpoints","request_seq":3,"seq":5,"success":true,"type":"response"} [2022-12-07 13:14:52:047][common/protocol.lua: 47][INFO ][send] {"body":{"breakpoints":[]},"command":"setFunctionBreakpoints","request_seq":4,"seq":6,"success":true,"type":"response"} [2022-12-07 13:14:52:047][common/protocol.lua: 47][INFO ][send] {"body":{"breakpoints":[{"id":2,"message":"Wait verify.","verified":false},{"id":3,"message":"Wait verify.","verified":false}]},"command":"setExceptionBreakpoints","request_seq":5,"seq":7,"success":true,"type":"response"} [2022-12-07 13:14:52:049][common/protocol.lua: 47][INFO ][send] {"body":{"sources":[]},"command":"loadedSources","request_seq":6,"seq":8,"success":true,"type":"response"} [2022-12-07 13:14:52:089][common/protocol.lua: 37][INFO ][recv] {"command":"configurationDone","type":"request","seq":7} [2022-12-07 13:14:52:090][common/protocol.lua: 47][INFO ][send] {"command":"configurationDone","request_seq":7,"seq":9,"success":true,"type":"response"} [2022-12-07 13:14:52:100][common/protocol.lua: 47][INFO ][send] {"body":{"breakpoint":{"id":2,"verified":true},"reason":"changed"},"event":"breakpoint","seq":10,"type":"event"} [2022-12-07 13:14:52:101][common/protocol.lua: 47][INFO ][send] {"body":{"breakpoint":{"id":3,"verified":true},"reason":"changed"},"event":"breakpoint","seq":11,"type":"event"} [2022-12-07 13:14:52:101][common/protocol.lua: 47][INFO ][send] {"body":{"reason":"started","threadId":1},"event":"thread","seq":12,"type":"event"} [2022-12-07 13:14:52:111][common/protocol.lua: 47][INFO ][send] {"body":{"reason":"new"},"event":"loadedSource","seq":13,"type":"event"} [2022-12-07 13:14:52:111][common/protocol.lua: 47][INFO ][send] {"body":{"reason":"new"},"event":"loadedSource","seq":14,"type":"event"} [2022-12-07 13:14:52:111][common/protocol.lua: 47][INFO ][send] {"body":{"reason":"new","source":{"name":"init.lua","path":"d:/User/Desktop/hihikid/app/assets/src/init.lua"}},"event":"loadedSource","seq":15,"type":"event"} [2022-12-07 13:14:52:112][common/protocol.lua: 47][INFO ][send] {"body":{"reason":"entry","threadId":1},"event":"stopped","seq":16,"type":"event"} [2022-12-07 13:14:52:112][common/protocol.lua: 37][INFO ][recv] {"command":"threads","type":"request","seq":8} [2022-12-07 13:14:52:121][common/protocol.lua: 47][INFO ][send] {"body":{"threads":[{"id":1,"name":"Thread (1)"}]},"command":"threads","request_seq":8,"seq":17,"success":true,"type":"response"} [2022-12-07 13:14:52:151][common/protocol.lua: 37][INFO ][recv] {"command":"threads","type":"request","seq":9} [2022-12-07 13:14:52:154][common/protocol.lua: 47][INFO ][send] {"body":{"threads":[{"id":1,"name":"Thread (1)"}]},"command":"threads","request_seq":9,"seq":18,"success":true,"type":"response"} [2022-12-07 13:14:52:182][common/protocol.lua: 37][INFO ][recv] {"command":"stackTrace","arguments":{"threadId":1,"startFrame":0,"levels":1},"type":"request","seq":10} [2022-12-07 13:14:52:195][common/protocol.lua: 47][INFO ][send] {"body":{"stackFrames":[{"column":1,"id":16777216,"line":44,"name":"(main)","presentationHint":"normal","source":{"name":"init.lua","path":"d:/User/Desktop/hihikid/app/assets/src/init.lua"}}],"totalFrames":65536},"command":"stackTrace","request_seq":10,"seq":19,"success":true,"type":"response"} [2022-12-07 13:14:52:213][common/protocol.lua: 37][INFO ][recv] {"command":"stackTrace","arguments":{"threadId":1,"startFrame":0,"levels":20},"type":"request","seq":11} [2022-12-07 13:14:52:230][common/protocol.lua: 47][INFO ][send] {"body":{"reason":"new","source":{"name":"bootstrap.lua","path":"D:/User/Desktop/hihikid/app/assets/src/bootstrap.lua"}},"event":"loadedSource","seq":20,"type":"event"} [2022-12-07 13:14:52:230][common/protocol.lua: 47][INFO ][send] {"body":{"stackFrames":[{"column":1,"id":16777216,"line":44,"name":"(main)","presentationHint":"normal","source":{"name":"init.lua","path":"d:/User/Desktop/hihikid/app/assets/src/init.lua"}},{"column":0,"id":16777217,"line":0,"name":"require","presentationHint":"label"},{"column":1,"id":16777218,"line":21,"name":"(main)","presentationHint":"normal","source":{"name":"bootstrap.lua","path":"D:/User/Desktop/hihikid/app/assets/src/bootstrap.lua"}}],"totalFrames":65536},"command":"stackTrace","request_seq":11,"seq":21,"success":true,"type":"response"} [2022-12-07 13:14:52:244][common/protocol.lua: 37][INFO ][recv] {"command":"threads","type":"request","seq":12} [2022-12-07 13:14:52:250][common/protocol.lua: 47][INFO ][send] {"body":{"threads":[{"id":1,"name":"Thread (1)"}]},"command":"threads","request_seq":12,"seq":22,"success":true,"type":"response"} [2022-12-07 13:14:52:633][common/protocol.lua: 37][INFO ][recv] {"command":"scopes","arguments":{"frameId":16777216},"type":"request","seq":13} [2022-12-07 13:14:52:633][common/protocol.lua: 37][INFO ][recv] {"command":"stackTrace","arguments":{"threadId":1,"startFrame":3,"levels":19},"type":"request","seq":14} [2022-12-07 13:14:52:648][common/protocol.lua: 47][INFO ][send] {"body":{"scopes":[{"expensive":false,"name":"Parameter","variablesReference":16777217},{"expensive":false,"name":"Local","variablesReference":16777218},{"expensive":false,"name":"Upvalue","variablesReference":16777219},{"expensive":true,"indexedVariables":1,"name":"Global","namedVariables":64,"variablesReference":16777220},{"expensive":true,"name":"Standard","variablesReference":16777221}]},"command":"scopes","request_seq":13,"seq":23,"success":true,"type":"response"} [2022-12-07 13:14:52:648][common/protocol.lua: 47][INFO ][send] {"body":{"stackFrames":[],"totalFrames":65536},"command":"stackTrace","request_seq":14,"seq":24,"success":true,"type":"response"} [2022-12-07 13:14:52:679][common/protocol.lua: 37][INFO ][recv] {"command":"variables","arguments":{"variablesReference":16777217},"type":"request","seq":15} [2022-12-07 13:14:52:691][common/protocol.lua: 47][INFO ][send] {"body":{"variables":[{"evaluateName":"select(1,...)","memoryReference":"memory_1x1","name":"[vararg 1]","type":"string","value":"'init'","variablesReference":0},{"evaluateName":"select(2,...)","memoryReference":"memory_1x2","name":"[vararg 2]","type":"string","value":"'src/init.lua'","variablesReference":0}]},"command":"variables","request_seq":15,"seq":25,"success":true,"type":"response"}

actboy168 commented 1 year ago

直接贴内容会被转义,最好是上传文件,或者使用```语法

zhongfq commented 1 year ago

client.log

actboy168 commented 1 year ago

从日志上看没有任何问题。你可能需要自己调试一下。把这里的注释打开,就可以把print输出到在log里。 https://github.com/actboy168/lua-debug/blob/a50d25db2285289b638246df429671c3e67da1cf/extension/script/backend/worker.lua#L104

从流程上说,DA先收到了设置断点的请求,但此时代码仍未加载,所以会在这里将断点信息储存起来。 https://github.com/actboy168/lua-debug/blob/a50d25db2285289b638246df429671c3e67da1cf/extension/script/backend/worker/breakpoint.lua#L230-L234

然后代码加载时再将断点信息取出。 https://github.com/actboy168/lua-debug/blob/a50d25db2285289b638246df429671c3e67da1cf/extension/script/backend/worker/breakpoint.lua#L274-L286

如果一切都正常的情况下会执行到verifyBreakpoint这个函数。所以你可以先弄清楚,是否执行到了verifyBreakpoint

zhongfq commented 1 year ago

谢谢了,找到问题了,最后追踪到undump那里没有,我修改了字节码的顺序,导致你的解析不成功

actboy168 commented 1 year ago

如果这里改用compat_dump来计算可能能解决修改字节码的问题。

https://github.com/actboy168/lua-debug/blob/05685dd25321301058dc77e9a4a97aead070761b/extension/script/backend/worker/evaluate.lua#L119-L128

zhongfq commented 1 year ago

估计也不能,因为我也调整了dump的顺序,跟你的undump的顺序不一致,在hook的回调中,不是可以得到lineinfo的相关信息,为啥还要你你缓存一份代码,计算lineinfo呢