lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Tue, Mar 2, 2010 at 7:31 PM, steve donovan <steve.j.donovan@gmail.com> wrote:
> On Tue, Mar 2, 2010 at 7:14 PM, Saurabh <saurabhcv@yahoo.com> wrote:
>> I am not sure if my previous post made it.
>
> Oh it did! It is already making me feel guilty....

Sufficiently guilty that I had a look; here is a little tutorial on
how to debug C extensions and Lua with scite-debug.

I note that the published documentation
(http://scitedebug.luaforge.net/#debug_scripts) is a bit behind the
times; I shall update this. The documentation.html which you will find
in the download is more recent.

If you go to the tests directory (easiest way to find this is to use
Options|Open Lua startup File and then do file open from this
directory) you will find testlfs.lua, plus lfs.c.

You will first need to build lfs.c with debugging information. Put
this line at the very start of lfs.c

// build@ gcc -shared -g lfs.c -o lfs.so

This overrides the usual meaning of 'build' (F7) which is to look for
a makefile. Do F7 to build lfs.so

Now, you have to set the SciTE debug.target variable. The output pane
acts as a SciTE Lua prompt, so typing Lua statements like '= 10 + 20'
will give you the result. This is certainly useful as a quick
calculator, but you can also use this to set SciTE variables. so this
command will set the variable:

$debug.target=[n]:gdb;lua;testlfs.lua

(You can also put 'debug.target=[n]:gdb;lua;testlfs.lua' in the local
SciTE config file, (Options|Open Local Options File))

The meaning of the value is as follows: use gdb to debug testlfs.lua
using the executable lua which is without debug symbols (hence the
[n])  You can use a debug version of Lua itself but this can get messy
since you will be stepping into Lua all the time.  Any executable with
embedded Lua can be substituted (such as SciTE itself); use [n] unless
you have compiled the executable with debug info and do want to step
into it.

Now, go to testlfs.lua and set a breakpoint (F9) on the third line
(print 'hey'). Start the debugger with Alt+R and execution should stop
at this line.  Alt+C (step) should take you through, and if all goes
well, you will enter lfs.c when you step into
'print(lfs.currentdir())'.

Please tell me how this goes and I can help with troubleshooting; this
process could certainly be made a bit simpler with an extra dialog
box! There is a known issue where SciTE hangs if you run the debugger
without any breakpoints.

PS. This process actually works with Lua for Windows as well, except
that you will need a mingw-compiled version of Lua (hence the feature
is not advertised)

steve d.