可以附加到进程的Lua调试器

发布于 2024-12-20 07:19:15 字数 640 浏览 2 评论 0原文

我的公司有一个程序,它在运行时使用嵌入的 Lua,从磁盘加载 .lua 文件并重复执行其中定义的函数。

有没有办法附加到正在运行的进程并在我的 .lua 文件中设置断点? GUI 断点的第三方 IDE。)

(我接受 gdb 风格的命令行调试作为 Lua 发行版的一部分,或者可能是提供类似 Visual Studio的 考虑到运行时从磁盘加载随机文件的性质,我的要求完全荒谬且不可能?

编辑:看起来这并不是无意义的,因为Lua自己的debug.getinfo()函数可以确定给定函数的源文件,并且debug.sethook() 允许输入的每行新代码的回调。因此,从磁盘加载源代码并能够判断解释器何时执行该文件中的特定代码行是合理的。问题仍然是:我如何锁定具有 Lua 解释器的现有进程并注入我自己的跟踪函数(然后可以监视文件/行号对并暂停执行)?

My company has a program that uses Lua embedded in its runtime, loading up .lua files from disk and executing functions defined in them repeatedly.

Is there a way to attach to the running process and set breakpoints in my .lua files? (I'd accept either gdb-style command-line debugging as part of the Lua distribution, or perhaps a third-party IDE that provides Visual-Studio-like GUI breakpoints.)

Or is what I'm asking for entirely nonsensical and impossible given the nature of the runtime loading up random files from disk?

Edit: Looks like it's not nonsensical, given that Lua's own debug.getinfo() function can determine the source file for a given function, and debug.sethook() allows a callback for each new line of code entered. So, it's reasonable to load source code from disk and be able to tell when the interpreter is executing a particular line of code from that file. The question remains: how do I latch onto an existing process that has a Lua interpreter and inject my own trace function (which can then watch for file/line number pairs and pause execution)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

最舍不得你 2024-12-27 07:19:15

如果您可以修改 .lua 文件,则可以在需要调试的任何内容之前插入以下调用:

require 'remdebug.engine'.start()

它会启动 RemDebug Lua 调试器引擎并尝试连接到控制器。如果无法连接,它将继续正常运行。我对调试器引擎进行了一些修复,例如处理临时变量,我的学生正在研究调试器 GUI(明年发布)。

同时,您可以尝试 Lua 开发工具 是否适合您。它具有类似于 RemDebug 的调试器,应该可以设置为如下:

require("debugger")(host, port, idekey)

或者,您可以使用 SciTE-debug,它是SciTE 编辑器,并且可以作为 RemDebug 的控制器。只需确保在 Lua 代码中的某个位置插入对 remdebug.engine.start 的调用,并将其插入到 SciTE 输出窗口中:

:debug.target=remote.lua

当您启动程序时,SciTE 应显示源代码和当前行。

If you can modify the .lua files, you can insert the following call just before anything you need to debug:

require 'remdebug.engine'.start()

It starts the RemDebug Lua debugger engine and tries to connect to a controller. If it cannot connect, it will just continue running as normal. I did some fixes to the debugger engine, such as dealing with temporary variables, and my student is working on a debugger GUI (due next year).

In the meantime, you can try if Lua Development Tools works for you. It features a debugger similar to RemDebug, which should be possible to set up as follows:

require("debugger")(host, port, idekey)

Alternatively, you can use SciTE-debug, which is an extension to the SciTE editor, and can serve as a controller to RemDebug. Just make sure you insert the call to remdebug.engine.start somewhere in your Lua code and insert this into the SciTE output window:

:debug.target=remote.lua

When you start your program, SciTE should show the source and current line.

甜妞爱困 2024-12-27 07:19:15

我一直在使用 Decoda 编辑器。它允许您附加到正在运行的 C++ 应用程序,之后它检测到您正在 C++ 代码中运行 Lua 解释器并显示您的 Lua 源代码,您可以在其中像往常一样添加断点并检查变量。

I've been using Decoda editor for that. It allows you to attach to a running C++ application, after that it detects that you're running a Lua Interpreter within your C++ code and show your Lua source code, where you can add beakpoints and inspect variables as usual.

不甘平庸 2024-12-27 07:19:15

这是我经过多次搜索后使用的替代方案。如果你有一个加载 lua 的外部可执行文件,我会在几分钟内完成它。该操作非常敏感,它有一个交互式调试器,可以加载您的代码,您可以交互式地放置调试点。它没有编辑器,但我使用 scite 或 crimson 编辑器并启动可执行文件,主 lua 模块中的一行启用调试器。

http://www.cushy-code.com/grld/ - 此链接似乎已失效现在

我已经转移到 eclipse.org/ldt 它有一个 ide 和集成调试器,推荐

hth

This is an alternative I use after much searching. If you have an external executable that loads lua, I got this working in a few minutes. The op is very responsive, it has an interactive debugger which loads your code you can place debug points interactively. It doesn't have an editor, but I use scite or crimson editor and start the executable, one line in your main lua module enables the debugger.

http://www.cushy-code.com/grld/ - this link seems dead now

I've moved to eclipse.org/ldt it has an ide and integrated debugger, recommended

hth

靑春怀旧 2024-12-27 07:19:15

IntelliJ 的 Lua 插件有一个工作调试器,无需特殊设置而不是指向你的 Lua 解释器。

这是它的截屏:

http://www.screencast.com/t/CBWIkoZPg

The Lua plugin for IntelliJ has a working debugger with no special setup required other than pointing to your Lua interpreter.

Here's a screencast of it:

http://www.screencast.com/t/CBWIkoZPg

辞别 2024-12-27 07:19:15

与 Michal Kottman 描述的类似,我实现了一个基于 RemDebug 的调试器,但具有其他修复和功能(在 github 上:https ://github.com/pkulchenko/MobDebug)。

您可以在要开始调试的位置使用 require("mobdebug").start("localhost", 8171) 更新您的 .lua 文件。然后,您可以使用命令行调试器来执行命令、设置断点、计算/执行表达式等。

作为替代方案,您可以使用 ZeroBrane Studio IDE,它与调试器集成,并为您提供了一个前端加载代码并在漂亮的 GUI 中执行相同的调试器命令。如果您想查看 IDE 的运行情况,我在这里有一个简单的演示:http://notebook.kulchenko.com/zerobrane/live-coding-in-lua-bret-victor-style

Similar to what Michal Kottman described, I have implemented a debugger based on RemDebug, but with additional fixes and features (on github: https://github.com/pkulchenko/MobDebug).

You can update your .lua file with require("mobdebug").start("localhost", 8171) at the point where you want the debugging to start. You can then use the command line debugger to execute commands, set breakpoints, evaluate/execute expressions and so on.

As an alternative, you can use ZeroBrane Studio IDE, which integrates with the debugger and gives you a front-end to load your code and execute same debugger commands in a nice GUI. If you want to see the IDE in action, I have a simple demo here: http://notebook.kulchenko.com/zerobrane/live-coding-in-lua-bret-victor-style.

最偏执的依靠 2024-12-27 07:19:15

您可能应该使用 Decoda
转到调试->流程-> Attach 附加您的流程。这应该可以正常工作。

You should probably use Decoda.
Go to Debug -> Processes -> Attach to attach your process. This should work fine.

输什么也不输骨气 2024-12-27 07:19:15

嗯,最简单的方法就是这个,感谢天才作者
https://github.com/slembcke/debugger.lua

你不需要设置一个远程调试服务器,只需要一个文件,然后简单地调用 dbg() 就会暂停,就像 gdb 一样

,也附带了一个教程,请查看。

Well the easiest way is this, thanks to the genius author
https://github.com/slembcke/debugger.lua

you don't need to setup a remote debug server ,just require one file,and simplely call dbg() and it will pause,just like gdb

an tutorial is also shipped with it, check it out.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文