[2.1.17] Debugger does not load correct source file when stepping

Post your bugs and problems so we can fix them.
User avatar
hgschmie
Fast Inserter
Fast Inserter
Posts: 234
Joined: Tue Feb 06, 2024 5:18 am
Contact:

[2.1.17] Debugger does not load correct source file when stepping

Post by hgschmie »

FMTK 2.1.9

Stepping (using F7) through a mod. After receiving a `on_pre_player_mined_item` event, the debugger stops on this breakpoint:
Screenshot 2026-09-04 at 23.59.46.png
Screenshot 2026-09-04 at 23.59.46.png (86.54 KiB) Viewed 238 times
This code lives in "scripts/controller.lua", lines 233-241:
Screenshot 2026-09-05 at 00.00.06.png
Screenshot 2026-09-05 at 00.00.06.png (104.8 KiB) Viewed 238 times
Pressing F7 should step the debugger to this function. The execution actually does so, however, vscode shows this:
Screenshot 2026-09-05 at 00.00.14.png
Screenshot 2026-09-05 at 00.00.14.png (72.12 KiB) Viewed 238 times
which is line 234 (correct!) but not in scripts/controller.lua but in "scripts/event-setup.lua" (which is the same file that "serialize_config" is in)

Stepping through the code using F7 gets the debugger to the end of the function correctly while showing the wrong source file:
Screenshot 2026-09-05 at 00.00.35.png
Screenshot 2026-09-05 at 00.00.35.png (86.43 KiB) Viewed 238 times
(this is line 240 in scripts/event-setup.lua, not line 240 in scripts/controller.lua, which is the code that the debugger has executed)

Pressing F7 here returns correctly.

dap trace log attached. The relevant parts start around ""seq":6932" (line 6961).
Attachments
dap-trace.log
(2.31 MiB) Downloaded 6 times
justarandomgeek
Filter Inserter
Filter Inserter
Posts: 332
Joined: Fri Mar 18, 2016 4:34 pm
Contact:

Re: [2.1.17] Debugger does not load correct source file when stepping

Post by justarandomgeek »

the trace you have provided does not seem to match these over-cropped screenshots (at no point does it include a stack trace for any of the shown function names), and there is not enough information to attempt to recreate the issue.
User avatar
hgschmie
Fast Inserter
Fast Inserter
Posts: 234
Joined: Tue Feb 06, 2024 5:18 am
Contact:

Re: [2.1.17] Debugger does not load correct source file when stepping

Post by hgschmie »

Tell me what you need and I can provide it. I can do a full screen video if needed. It is one of two issues I have with FMTK right now.

The log is from the session where I took the screenshots. If you say it does not match, maybe that is the problem.
User avatar
hgschmie
Fast Inserter
Fast Inserter
Posts: 234
Joined: Tue Feb 06, 2024 5:18 am
Contact:

Re: [2.1.17] Debugger does not load correct source file when stepping

Post by hgschmie »

Factorio 2.1.17
FMTK 2.1.9
VSCode 1.136.1

- clone https://github.com/hgschmie/factorio-mi ... -redux.git into "miniloader-redux" in your mod folder. Checkout the 2.2.1 tag
- open the mod code in vscode.
- put a breakpoint on line 178 in scripts/event-setup.lua

- create a new game under the debugger. Only base game mod and miniloader-redux (should show as version 2.2.1) mod
- use sandbox mode. click yes to all modal questions
- craft a new blue miniloader
- place the miniloader
- create a blueprint from the miniloader

- this should hit the breakpoint at line 178. This is where the video starts.

The attached dap-trace.log is from the exact session in the video.
Attachments
Screen Recording 2026-09-05 at 14.18.29.mp4
(8.4 MiB) Downloaded 4 times
dap-trace.log
(394.03 KiB) Downloaded 2 times
justarandomgeek
Filter Inserter
Filter Inserter
Posts: 332
Joined: Fri Mar 18, 2016 4:34 pm
Contact:

Re: [2.1.17] Debugger does not load correct source file when stepping

Post by justarandomgeek »

okay, i've replicated it now, investigating...
justarandomgeek
Filter Inserter
Filter Inserter
Posts: 332
Joined: Fri Mar 18, 2016 4:34 pm
Contact:

Re: [2.1.17] Debugger does not load correct source file when stepping

Post by justarandomgeek »

it looks like this is specifically an issue with tailcalls (of metamethods? not sure yet...), so as a workaround for now, putting parens around the return makes it step to the correct location:

Code: Select all

return (This.MiniLoader:serializeConfiguration(entity))
justarandomgeek
Filter Inserter
Filter Inserter
Posts: 332
Joined: Fri Mar 18, 2016 4:34 pm
Contact:

Re: [2.1.17] Debugger does not load correct source file when stepping

Post by justarandomgeek »

DebugAdapter was incorrectly holding cached information about the caller function after the tailcall hook, when the callee got moved up into that slot (and thus now matches by address), and only refreshing the line number, thus leading to the incorrect "merged" stack report with the callee's line number in the caller's file.
Post Reply

Return to “Bug Reports”