The LUA built-in debugger usage detailed

Source: Internet
Author: User
Tags command line lua stack trace

This article mainly introduces Lua's built-in debugger usage and is useful in programming debug operations, and friends can refer to

LUA provides a debug library that provides all the basic functionality to create your own debugger. Even so, there is no built-in LUA debugger, and Lua creates many debuggers for developers that are open source.

The features available in the Debug Lua library are listed in the table below along with its purpose.

The complete list of Lua debugging features in the list above is used frequently, using the above features and providing a more convenient debug library. Using these functions and creating your own debugger is rather complex and not the best choice. In any case, we'll see examples of using simple debugging features.

The code is as follows:

function MyFunction ()

Print (Debug.traceback ("Stack Trace"))

Print (Debug.getinfo (1))

Print ("Stack Trace End")

Return 10

End

MyFunction ()

Print (Debug.getinfo (1))

When we run the above program, we get the stack trace information, as shown in the following figure.

The code is as follows:

Stack Trace

Stack Traceback:

Test2.lua:2: In function ' MyFunction '

Test2.lua:8: in main chunk

[C]:?

Table:0054c6c8

Stack Trace End

In the example program above, the stack trace is printed by using the Debug.trace feature available in the Debug library. Debug.getinfo Gets the current table of the function.

Another example

We often need to know the local variables of a function to debug. To do this you can use the Setupvalue setting and use Getupvalue to get these local variables,. A simple example of this is shown below.

The code is as follows:

function Newcounter ()

Local n = 0

Local k = 0

return function ()

K = n

n = n + 1

return n

End

End

Counter = Newcounter ()

Print (counter ())

Print (counter ())

Local i = 1

Repeat

Name, val = debug.getupvalue (counter, i)

If Name then

Print ("Index", I, name, "=", Val)

if (name = = "N") Then

Debug.setupvalue (counter,2,10)

End

i = i + 1

End--If

Until not name

Print (counter ())

When we run the above program, we get the output below.

The code is as follows:

1

2

Index 1 k = 1

Index 2 n = 2

11

In this example, each counter is updated when it is invoked. You can use the Getupvalue function to get the current state of a local variable. The local variable is then set to a new value. Here, N is set to 2 before the operation is called. Using the Setupvalue function to update to 10, when the counter function is invoked, it returns 11 instead of 3.

Debug type

Command-line debugging

Graphical debugging

Command-line debugging

Command-Line debugging is the type of debugging that uses the command line to debug with commands and print reports. There are several command-line debuggers available in the following list.

Remdebug:remdebug is a remote debugger in Lua5.0 and 5.1. It can remotely control another LUA program execution, set breakpoints, and check the current state of the program. Remdebug can also debug Cgilua scripts.

A simple command-line interface debugger for clidebugger:lua5.1 is written in pure Lua. It does not depend on any other than the standard Lua5.1 library. It is inspired from Remdebug, but does not have its remote device.

Ctrace: A tool to track the LUA API calls.

A simple Lua command-line debugger for the Xdblua:windows platform.

Luainterface-debugger: This project is an extended Luainterface debugger. It is proposed to build on the Lua debug interface to a higher level. The interaction with the debugger is done through event and method calls.

RLDB: This is a remote LUA debugger with sockets that works for Windows and Linux. It can give you more functionality than any existing one.

Moddebug: This allows you to remotely control the execution of other LUA programs, set breakpoints, and check the current state of the program.

Graphical debugging

Graphical debugging provides the IDE with visual debugging of various states, such as variable values, stack trace information, and other related information. There is a visual representation that steps to perform a breakpoint to help the next step control, stepping, skipping and other buttons in the IDE.

There is the number of graphical Lua debuggers, which includes the following.

SciTE: Lua in the default Windows IDE provides a variety of debugging tools, such as breakpoints, one-step, step into, skip, view variables, and more.

Decoda: This is a remote debugging that supports graphical debuggers.

Zerobrane Studio:lua IDE integrates remote debugger, stack view, table view, remote console, static analyzer, etc. Works with Luajit,love2d,moai, and other LUA engines. In Windows,osx and Linux and open source.

Akdebugger:lua Eclipse Plug-in-debugger and editor.

Luaedit: This feature remote debugging, local debugging, syntax highlighting, automatic completion of the proposed list, parametric proposition engine, push breakpoint management (including breakpoint air-conditioning system and hit number), function list, global variables and local variables list, view, problem-solving-oriented management

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.