Lua Remote Debug

Everyday the debug

Unexpected errors may occur when a local project is deployed to a remote test server. To troubleshoot the problem, it might be:

Like this:

And then this:

The last is:

The most frightening thing is that it is difficult to get the desired information in the debug log at one time due to the stack relationship. It is often necessary to type the log layer by layer to get the desired debug information.

remote debug

The local server opens the port to call the breakpoint information of the remote server to the local server.

So how do you do that?

JetBrains’ “EmmyLua” plugin + mobDebug library

Local JetBrains adds EmmyLua plugin installation

Add the mobdebug package to the project debug directory and add configuration information

https://github.com/pkulchenko…

local mobdebug = require("debug.mobdebug");
mobdebug.rbasedir("/usr/local/openresty/nginx/lua/")  -- remote
mobdebug.lbasedir("/Users/wilburxu/lua/test/")  -- local
mobdebug.start("host.docker.internal", 28172);



PS: The breakpoint message is sent back to the remote server’s line, so the local server must ensure that the line is the same as that of the remote server.

Add debug Configuration locally

Send the request



And we’ll get the stack information that we want.

The basic structure of MobDebug

MOBDEBUG is a remote debugger implemented in pure Lua, which relies on Luasocket. The basic communication mode is to transmit the corresponding control instructions and execution results between the target program and the IDE in the form of a string. The data that MOBDEBUG interacts with the remote end is directly packaged as a string in Lua format.

Interaction protocol

The communication mode used by MOBDEBUG is responsive, that is, most of the time, it is the remote IDE that sends a Command to the debugging target program and then waits for the result returned by the debugging target. In the source code side of Emmylua, it maintains a Command queue. If the Command needs to respond, Only after the current Command has been processed will the remaining commands in the queue be sent.