Murga-Projects Forums
Debugging with murgaLua - Tutorial - Printable Version

+- Murga-Projects Forums (http://www.murga-projects.com/forum)
+-- Forum: Project Forums (/forumdisplay.php?fid=1)
+--- Forum: MurgaLua - General (/forumdisplay.php?fid=2)
+--- Thread: Debugging with murgaLua - Tutorial (/showthread.php?tid=390)


Debugging with murgaLua - Tutorial - JohnMurga - 10-13-2010 09:07 PM

MurgaLua now incorporates a customized version of remDebug.

Soon there will be a GUI for this, but until then here is how to use it.

Invocation :
  • The traditional remDebug way ...
    Adding the following to your code :
    require "remdebug.engine"
    remdebug.engine.start()
  • From the command line ...
    Invoking your program with :
    murgaLua -e "remdebug.engine.start();dofile ('test.lua')"
Tutorial :
  • Open two command line windows.
    One for the debug console, one from the program to be run.
  • Go to the tests/debug directory on both prompts.
  • Run the debug console on one prompt.
    murgaLua controller.lua
  • Switch to the other prompt and run the test program.
    murgaLua test.lua
  • Now switch back to the debug console.
    You should see a line that says "Paused at file" ...
  • Using the file path which is displayed for you type :
    setb "C:/murgaLua/tests/debug/test.lua" 22
  • Then try
    setw tab.foo == 8
  • Now lets try running it and see what happens, type :
    run
  • Now to see all the local variables try :
    eval murgaLua.debug.dumpTableAsLua(getfenv())

Cool huh :-)

Todo :
  • Testing :-)
  • FilterGlobals function, to return non-system global variables.
  • Decent UI.

Cheers
John de Murga


RE: Debugging with murgaLua - Tutorial - jpjacobs - 01-29-2011 07:07 AM

This really is cool. It enables really easy debugging, without mixing actual program output and debugging output! great Smile.

There is however one thing I can't get right: I'm having problems setting breakpoints. I tried setting the basedir before, and I tried all variations of:
  • setb test.lua 22
  • setb "test.lua" 22
  • setb /home/.../murgaLua/test/debug/test.lua 22
  • setb "/home/.../murgaLua/test/debug/test.lua" 22
When I enter the run command, it just runs the program all the way through, without breaking at the desired point. listb however lists the breakpoint.

Any idea what I'm doing wrong?

Edit: After fiddling a bit with strange setups (using the debugger to debug itself), I figured out what has happened: Apparently the standard controller hasn't got the brains to use a local path, or look in the local dir by default. If you give a basedir with basedir, then give it a local dir (so not starting with /) with respect to / (while in my opinion, it should be the current dir). I'll try to write up a patch for controller.lua to make it behave as expected.

Here's a patch: It works (at least for Linux) as I would expect:

Code:
34c33
< local basedir = ""
---
> local basedir = (lfs.currentdir() or ""):gsub("^/+",""):gsub("/+$","/") -- remove any leading / and add a trailing one.
203c202
<     local _, _, dir = string.find(line, "^[a-z]+%s+(.+)$")
---
>     local _, _, dir = string.find(line, "^[/a-z]+%s+(.+)$")
205,206c204,209
<       if not string.find(dir, "/$") then dir = dir .. "/" end
<       basedir = dir
---
>       if dir:match("^/+") then
>         dir = dir:gsub("^/+","")
>       else
>         dir = (lfs.currentdir() or ""):gsub("^/+","")..'/'..dir
>       end
>       basedir = dir:gsub("/+$","/")


Thanks,
Jan-Pieter