DarkMatter in Cyberspace
  • Home
  • Categories
  • Tags
  • Archives

Debug Erlang Program


Verified on Ubuntu 12.04 Desktop.

Assume debugged method is add2/2 in fordebug module as follows:

-module(fordebug). 
-export([add/3]). 
add(A1, A2, A3) when is_integer(A1), is_integer(A2), is_integer(A3) -> 
    add(A1, A2) * 100 + A3; 
add(_, _, _) -> error. 
add(A1, A2) when A1 >= 0, A2 >= 0 -> A1 + A2; 
add(_, _) -> -1. 

GUI Debugger

  1. Compile source files with "debug_info" flag: in erlang REPL window, c(fordebug, debug_info).;

  2. Start GUI debugger: debugger:start()., then "Monitor" window appears;

  3. Config source file breakpoint:

    i. [Module -> Interpret], choose the source file to be debuged(in Monitor window);

    i. in Monitor window, double click fordebug, then the "View Module" window appears, set breakpoint here;

  4. begin debug: in erlang REPL window, fordebug:add(3,4,5)., in Monitor window you can see a row under "PID", double click it, the "Attach Process" window appears, you can see source code at the top pannel, step, continue program execution by bottons at the center, see values of variables in the bottom-right pannel, and evaluate variables at the bottom-left pannel;

GUI debugger with the help of i module

use ih(). to show help messages of i module.Repeat above procedure:

c(fordebug, debug_info).

im(). % start Monitor window

ii(fordebug). % add mySrcFile to Monitor,

%% use iq(mySrcFile) to remove mySrcFile from Monitor

%% use il(). showing all interpreted modules

ib(fordebug, add, 2). % add breakpoint to at the first line of every clause of add/2

%% ir(). % clear all breakpoints

%% ipb(). % print all breakpoints

iaa([init]). % attach to a debugger process automatically

fordebug:add(4,6,8). % now Attach Process window appears, you can debug code in it

NOTE: when doing this in sublime text, erlang shell hangs after debug process ends. So it's recommended to debug in console.

Command-line Debugger(not complete)

dbg:start().

dbg:tracer().

dbg:tp(mySrcFile,

bingo.



Published

May 24, 2013

Last Updated

May 24, 2013

Category

Tech

Tags

  • debugger 2
  • erlang 15

Contact

  • Powered by Pelican. Theme: Elegant by Talha Mansoor