Sample ladebug sessions:

Using ladebug to Walkthrough Code

The purpose of this ladebug session is to show how to start using ladebug. It covers the how to use the following ladebug commands:

If you know gdb already, you will find using ladebug is almost the same as using gdb for those basic commands. For this example the source code is example.c and the input for the process is ex_input.

The first step in debugging is to compile the source with the debugging option. This is the -g option.

$ gcc -g example.c -o example
example.c: In function `add_list':
example.c:61: warning: assignment makes pointer from integer without a cast
$

After the source is compiled, you can run the executable in ladebug.

Before you start the debugger, make sure that you have correctly set the size information for your terminal; otherwise, the debugger's command line editing support may act unpredictably. For example, if your terminal is 47x80, you may need to set the following:

% stty rows 47 ; setenv LINES 47
% stty cols 80 ; setenv COLS 80
$ ladebug ./example
Welcome to the Ladebug Debugger Version 4.0-43
------------------ 
object file name: ./example 
Reading symbolic information ...done
(ladebug)

To begin to walk through the code set a breakpoint at the function main before you run the process so that you can stop the process and see which lines get executed.

(ladebug) stop in main
[#1: stop in int main(int, char**) ]
(ladebug)

Run the process.

(ladebug) run  ex_input
[1] stopped at [main:135 0x120001c20]
    135         if (argc != 2)
(ladebug)

To run the process one line of code type next.

(ladebug) next
stopped at [main:141 0x120001c84]
    141         fp = fopen(argv[1], "r");
(ladebug)

In ladebug you can repeat the previous command by typing a carriage return.

(ladebug) next
stopped at [main:142 0x120001cb0]
    142         if (fp == NULL)
(ladebug)
(ladebug) next                                                                 
stopped at [main:148 0x120001ce8]
    148         init_queue(&q);
(ladebug) next                                                                 
stopped at [main:150 0x120001cf4]
    150         fgets(line, sizeof(line), fp);
stopped at [main:151 0x120001d14]
    151         while (!(feof(fp)))
stopped at [main:156 0x120001d34]
    156                 if (line[0] == '?')
stopped at [main:159 0x120001d44]
    159                         int num = count_queue(&q);
stopped at [main:160 0x120001d58]
    160                         printf("queue is %d long\n",num);
queue is 0 long
stopped at [main:161 0x120001d78]
    161                         print_list(&q);
stopped at [main:164 0x120001d84]
    164                 } else if (line[0] == 'a')
stopped at [main:178 0x120001e24]
    178                 fgets(line, sizeof(line), fp);
stopped at [main:179 0x120001e44]
    179         }
stopped at [main:151 0x120001d14]
    151         while (!(feof(fp)))
stopped at [main:156 0x120001d34]
    156                 if (line[0] == '?') 

As you can see, next steps through the code a line at a time. Notice that next does not enter functions.

If you want to step through code and enter functions use the step command.

(ladebug) step

stopped at [main:167 0x120001d98]
    167                         if (1 == sscanf(&line[1],"%d",&data))
stopped at [main:168 0x120001dd0]
    168                                 add_queue(&q, data);
stopped at [add_queue:109 0x120001a94]
    109         assert(q != NULL);
(ladebug) 

step has entered the add_queue function.

(ladebug) step                                                                 
stopped at [add_queue:111 0x120001ad0]
    111         return add_list(q,data);
stopped at [add_list:58 0x1200017c4]
     58         assert(head != NULL);
stopped at [add_list:59 0x120001800]
     59         ptr = *head;
stopped at [add_list:61 0x12000180c]
     61         newptr = malloc(sizeof(LL));
stopped at [add_list:62 0x120001828]
     62         if (newptr == NULL) {
stopped at [add_list:66 0x120001854]
     66         newptr->data = data;

To examine data you can use the print command.

(ladebug) print newptr                                                         
0x140000940
(ladebug) print *newptr                                                        
struct linked_list {
  data = 0; 
  next = 0x0; 
}
(ladebug) print data                                                           
123
(ladebug) 

To kill the debug session use the kill command.

(ladebug) kill                                                                 
Process has exited
(ladebug)

To exit ladebug use the quit command.

(ladebug) quit                                                                 
$ 


  

                Summary of commands


        command          abbr     description
        format
        --------         -----    ------------
        run [args]       r        start program with args        
        next [count]     n        step count lines of code
        step [count]     s        step count lines of code
                                  including function calls
        stop in addr     bp       set breakpoint at addr        
        stop at [line]   b        set breakpoint at line number 
        print value      p        print the value
        kill             k        kill the process being debugged
        quit             q        quit ladebug


        name         definition                usage
        -----        -----------               ------

        args         command line arguments    -i
                     as if run from a shell    < input > output
        count        a number, default is 1    10
        addr         function                  main
        line         line number               "example.c":100
                                               0x120001c20
        value        variable, expression      loszFileName
                                               &pch1
                                               *poiVal[i]


The debugger has the following predefined aliases:

(ladebug) alias  
F1	print
F2	print 'F2 executes the command "F2 selected-text" - define alias F2'
F3	print 'F3 executes the command "F3 selected-text" - define alias F3'
S	next
Si	nexti
W	list $curline - 10:20
a	assign
att	attach
b	stop at
bp	stop in
c	cont
d	delete
det	detach
e	file
exit	quit
f	func
focus	ladebug multi select
g	goto
h	history
j	status
l	list
li	($cursrcpc)/10 i; set $cursrcpc = $cursrcpc + 40
n	next
ni	nexti
p	print
pb	printb
pd	printd
pi	printi
plist	show process all
po	printo
pr	printregs
ps	printf "%s",
pt	printt
px	printx
q	quit
r	rerun
ri	record input
ro	record output
s	step
si	stepi
source	playback input
sw	switch
switch	process
t	where
tlist	show thread
ts	where thread all
tset	thread
tstack	where thread all
u	list $curline - 9:10
w	list $curline - 5:10
wi	($curpc - 20)/10 i
wm	watch memory
wv	watch variable
Hosted by www.Geocities.ws

1