how to debug like the tool "decoda"? [message #977474] |
Fri, 09 November 2012 05:07  |
Eclipse User |
|
|
|
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 #983124 is a reply to message #978687] |
Tue, 13 November 2012 12:45   |
Eclipse User |
|
|
|
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 #990034 is a reply to message #989190] |
Mon, 10 December 2012 10:53  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.06250 seconds