Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » Lua Development Tools » how to debug like the tool "decoda"?(I want to debug the lua file called by a C program, how to do that?)
how to debug like the tool "decoda"? [message #977474] Fri, 09 November 2012 10:07 Go to next message
Guangcheng Huang is currently offline Guangcheng HuangFriend
Messages: 9
Registered: May 2012
Junior Member
I write some function in x.lua file, and I call the lua function from my C program. I want to debug the lua function called by the C program using Koneki/ldt just like the tool "decoda", how to do that?
Re: how to debug like the tool "decoda"? [message #977742 is a reply to message #977474] Fri, 09 November 2012 14:38 Go to previous messageGo to next message
Marc Aubry is currently offline Marc AubryFriend
Messages: 86
Registered: August 2012
Member
Hi Guangcheng,

Maybe by using the "Attach Debug" as explain here: http://wiki.eclipse.org/Koneki/LDT/Developer_Area/User_Guides/User_Guide_0.8#Remote_Debug

If you use a 0.9 version of LDT, a better and more complete documentation can be found here: http://wiki.eclipse.org/Koneki/LDT/Developer_Area/User_Guides/User_Guide_0.9#Debug
And download the debugger file here.

If it doesn't work please explain your case with more details.

Marc
Re: how to debug like the tool "decoda"? [message #977747 is a reply to message #977474] Fri, 09 November 2012 14:39 Go to previous messageGo to next message
Marc Aubry is currently offline Marc AubryFriend
Messages: 86
Registered: August 2012
Member
edit: duplicate message -_-

[Updated on: Fri, 09 November 2012 14:40]

Report message to a moderator

Re: how to debug like the tool "decoda"? [message #978687 is a reply to message #977747] Sat, 10 November 2012 08:20 Go to previous messageGo to next message
Guangcheng Huang is currently offline Guangcheng HuangFriend
Messages: 9
Registered: May 2012
Junior Member
thank you!
Re: how to debug like the tool "decoda"? [message #983124 is a reply to message #978687] Tue, 13 November 2012 17:45 Go to previous messageGo to next message
Guangcheng Huang is currently offline Guangcheng HuangFriend
Messages: 9
Registered: May 2012
Junior Member
1, My lua file is:
-- t.lua
function L_add(x, y)
return x + y
end

2, My C++ program file is:
// test.cpp

#include <stdio.h>

#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */

#include <lua.h> // lua是用纯c语言写的
#include <lualib.h>
#include <lauxlib.h>

#ifdef __cplusplus
}
#endif /* __cplusplus */

lua_State* L = NULL;

int Add(int x, int y)
{
int savedTop = lua_gettop(L);
int sum = 0;

lua_getglobal(L, "L_add"); // 'L_add' is the function defined in file 't.lua'
lua_pushnumber(L, x); // the first argument
lua_pushnumber(L, y); // the second argument
lua_call(L, 2, 1); // call the function with 2 arguments, return 1 result

sum = (int) lua_tonumber(L, -1);

lua_pop(L, 1);
lua_settop(L, savedTop);

return sum;
}

int main(int argc, char* argv[])
{
L = luaL_newstate();
if (!L)
{
return -1;
}

luaL_dofile(L, "t.lua");

while (true)
{
int sum = Add(10, 15);
printf("The sum is %d\n", sum);

//sleep(1);
}

lua_close(L);
return 0;
}

3, In the C++ program, it calls lua function 'L_add'. Now I want to use koneki/ldt to debug it. I toggle a breakpoint in 'L_add' function and start the C++ program. I expect the breakpoint will be hit when 'L_add' is called in the C++ program. I really confused how to do that even after I read the manual you give. Would you please tell me step by step? Thank you very much!

By addition, I advise you write your manual by runnable example otherwise by spoon-feeding. Welcome to use my code snippet here!
(PS. some diagrams in the manual mismatch the 0.9 milestone executable version itself)


Re: how to debug like the tool "decoda"? [message #989190 is a reply to message #977742] Wed, 05 December 2012 06:49 Go to previous messageGo to next message
Guangcheng Huang is currently offline Guangcheng HuangFriend
Messages: 9
Registered: May 2012
Junior Member
Are you there, my friend??
Re: how to debug like the tool "decoda"? [message #990034 is a reply to message #989190] Mon, 10 December 2012 15:53 Go to previous message
Marc Aubry is currently offline Marc AubryFriend
Messages: 86
Registered: August 2012
Member
Hi Guangcheng,

Sorry for the late response.

Can you be a bit more precise of what you don't understand in the documentation ? Maybe some point can be unclear.

Otherwise, here some simple step to perform lua attached debug:

first) Ensure to call the lua code by putting a print in the lua, or return a value and retrieve this one in the C code.

requirement) the lua global variable "package.path" in the lua must contains a path to luasocket libraries/binaries.

1) Add the following line at the beginning of your lua file:
require("debugger")()
-- t.lua
function L_add(x, y)
return x + y
end


2) Create and launch a attach debug configuration using the "Run/Debug Configuration" top menu. You don't have to configure the launch configuration as default values are pretty fine.

3) Launch the C program to call the lua code.

Please tell me if you still have some trouble.

Marc
Previous Topic:LDT debugging the LÖVE framework
Next Topic:No way to code to make code hinting to work
Goto Forum:
  


Current Time: Sat Apr 20 00:09:53 GMT 2024

Powered by FUDForum. Page generated in 0.03761 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top