EmmyLua / IntelliJ-EmmyLua

Lua IDE/Debugger Plugin for IntelliJ IDEA
https://emmylua.github.io
Apache License 2.0
1.72k stars 285 forks source link

Can't break point lua with Emmy Debugger(NEW) #561

Closed ahyee closed 10 months ago

ahyee commented 10 months ago

Environment(环境)

name version
IDEA version 2022.3.3
EmmyLua version 1.3.8
OS Window 11

What are the steps to reproduce this issue?(重现步骤?)

  1. Run debugger in rider and insert a breakpoint
  2. Run unity 2022.3.5 and try to hit the breakpoint

What happens?(出现什么问题?)

The IDE didn't stop at the breakpoint despite the log was printed out. And also the IDE showed its connected as below

Server(localhost:9966) open successfully, wait for connection... Connected.

What were you expecting to happen?(期望?)

Expect the IDE to stop at breakpoint

Any logs, error output, etc?(有没有什么log, error输出?)

(If it’s long, please paste to https://ghostbin.com/ and insert the link here.)

Any other comments?(其它说明)

My Lua files was located outside of Unity Assets folder, not sure if this matter.

CppCXY commented 10 months ago

This may be because your chunkname does not comply with the general rules of Lua. The general format for a Lua chunkname is aaa/b/ccc.lua. You can check the chunkname by printing debug.getinfo(1).source or use dbg.breakHere() to forcefully break and inspect it. If you are developing with Unity's xLua, you can modify the custom loader. If you are using a different framework, you can try modifying the usage of the lua loadbuffer interface.

ahyee commented 10 months ago

This is what I printed out with debug.getinfo

@UI/UIVillage

but the break point still didnt worked.

CppCXY commented 10 months ago

you can try dbg.breakHere(), this code needs to be inserted after dbg.tcpConnect, is your editor Rider?

ahyee commented 10 months ago

Yes I'm using Rider. I notice some of my lua file used . instead of /. Will it affect the file that i going to debug which is using /?

CppCXY commented 10 months ago

It is correct to use require 'aaaa.bbbbbbbb.cccccc' in the code, but the corresponding chunkname needs to be changed to a/b/c. Have you tried using dbg.breakHere()?

ahyee commented 10 months ago

dbg.breakHere() do work however I cant step over etc for it

CppCXY commented 10 months ago

Files outside of the assets may not be indexed by Rider. You can try using other editors like Visual Studio Code or IntelliJ IDEA.

ahyee commented 10 months ago

I see.. I will test out others. I using Xlua in Unity. Is this what you mean by modify custom loader?

luaEnv.AddLoader((ref string filePath) => ReadFile(filePath));

private static byte[] ReadFile(string path) { if (path == "emmy_core") return null;

    path = path.Replace('.', '/');
    var fileFullPath = $"{FileService.GetAssetRootPath()}/lua_root/{path}.lua";
    return System.IO.File.ReadAllBytes(fileFullPath);
}
CppCXY commented 10 months ago

You can take a look at the documentation for the AddLoader function. It requires you to return the real path to filePath. In other words, you need to modify the ReadFile parameter to be ref string path and assign fileFullPath to path.

ahyee commented 10 months ago

thanks