1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset= ISO-8859-1">
<TITLE>
The debugger (ocamldebug)
</TITLE>
</HEAD>
<BODY >
<A HREF="manual025.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="manual027.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
<A HREF="index.html"><IMG SRC ="contents_motif.gif" ALT="Contents"></A>
<HR>
<H1>Chapter 13: The debugger (ocamldebug)</H1> <A NAME="c:debugger"></A>
This chapter describes the Objective Caml source-level replay debugger
<TT>ocamldebug</TT>.<BR>
<BR>
<FONT COLOR=purple>Unix:</FONT>
<BLOCKQUOTE> The debugger is available on Unix systems that provides
BSD sockets.
</BLOCKQUOTE>
<FONT COLOR=purple>Windows:</FONT>
<BLOCKQUOTE> The debugger is not available. </BLOCKQUOTE>
<H2>13.1 Compiling for debugging</H2>Before the debugger can be used, the program must be compiled and
linked with the <TT>-g</TT> option: all <TT>.cmo</TT> and <TT>.cma</TT> files that are part
of the program should have been created with <TT>ocamlc -g</TT>, and they
must be linked together with <TT>ocamlc -g</TT>.<BR>
<BR>
Compiling with <TT>-g</TT> entails no penalty on the running time of
programs: object files and bytecode executable files are bigger and
take longer to produce, but the executable files run at
exactly the same speed as if they had been compiled without <TT>-g</TT>.<BR>
<BR>
<H2>13.2 Invocation</H2>
<H3>13.2.1 Starting the debugger</H3>The Objective Caml debugger is invoked by running the program
<TT>ocamldebug</TT> with the name of the bytecode executable file as first
argument:
<PRE>
ocamldebug [<I>options</I>] <I>program</I> [<I>arguments</I>]
</PRE>
The arguments following <I>program</I> are optional, and are passed as
command-line arguments to the program being debugged. (See also the
<TT>set arguments</TT> command.)<BR>
<BR>
The following command-line options are recognized:
<DL COMPACT=compact>
<DT>
<TT>-I </TT><I>directory</I><DD>
Add <I>directory</I> to the list of directories searched for source
files and compiled files. (See also the <TT>directory</TT> command.)<BR>
<BR>
<DT><TT>-s </TT><I>socket</I><DD>
Use <I>socket</I> for communicating with the debugged program. See the
description of the command <TT>set socket</TT> (section <A HREF="manual026.html#s:communication">13.8.6</A>)
for the format of <I>socket</I>.<BR>
<BR>
<DT><TT>-c </TT> <I>count</I><DD>
Set the maximum number of simultaneously live checkpoints to <I>count</I>.<BR>
<BR>
<DT><TT>-cd </TT> <I>directory</I><DD>
Run the debugger program from the working directory <I>directory</I>,
instead of the current directory. (See also the <TT>cd</TT> command.)<BR>
<BR>
<DT><TT>-emacs</TT><DD>
Tell the debugger it is executed under Emacs. (See
section <A HREF="manual026.html#s:inf-debugger">13.10</A> for information on how to run the
debugger under Emacs.)
</DL>
<H3>13.2.2 Exiting the debugger</H3>The command <TT>quit</TT> exits the debugger. You can also exit the debugger
by typing an end-of-file character (usually <TT>ctrl-D</TT>).<BR>
<BR>
Typing an interrupt character (usually <TT>ctrl-C</TT>) will not exit the
debugger, but will terminate the action of any debugger command that is in
progress and return to the debugger command level. <BR>
<BR>
<H2>13.3 Commands</H2> <A NAME="s:debugger-commands"></A>A debugger command is a single line of input. It starts with a command
name, which is followed by arguments depending on this name. Examples:
<PRE>
run
goto 1000
set arguments arg1 arg2
</PRE>A command name can be truncated as long as there is no ambiguity. For
instance, <TT>go 1000</TT> is understood as <TT>goto 1000</TT>, since there are no
other commands whose name starts with <TT>go</TT>. For the most frequently
used commands, ambiguous abbreviations are allowed. For instance, <TT>r</TT>
stands for <TT>run</TT> even though there are others commands starting with
<TT>r</TT>. You can test the validity of an abbreviation using the <TT>help</TT> command.<BR>
<BR>
If the previous command has been successful, a blank line (typing just
<TT>RET</TT>) will repeat it.<BR>
<BR>
<H3>13.3.1 Getting help</H3>The Objective Caml debugger has a simple on-line help system, which gives
a brief description of each command and variable.<BR>
<BR>
<DL COMPACT=compact>
<DT>
<TT>help</TT><DD>
Print the list of commands.<BR>
<BR>
<DT><TT>help </TT><I>command</I><DD>
Give help about the command <I>command</I>.<BR>
<BR>
<DT><TT>help set </TT><I>variable</I>, <TT>help show </TT><I>variable</I><DD>
Give help about the variable <I>variable</I>. The list of all debugger
variables can be obtained with <TT>help set</TT>.<BR>
<BR>
<DT><TT>help info </TT><I>topic</I><DD>
Give help about <I>topic</I>. Use <TT>help info</TT> to get a list of known topics.
</DL>
<H3>13.3.2 Accessing the debugger state</H3><DL COMPACT=compact>
<DT>
<TT>set </TT><I>variable</I> <I>value</I><DD>
Set the debugger variable <I>variable</I> to the value <I>value</I>.<BR>
<BR>
<DT><TT>show </TT><I>variable</I><DD>
Print the value of the debugger variable <I>variable</I>.<BR>
<BR>
<DT><TT>info </TT><I>subject</I><DD>
Give information about the given subject.
For instance, <TT>info breakpoints</TT> will print the list of all breakpoints.
</DL>
<H2>13.4 Executing a program</H2>
<H3>13.4.1 Events</H3>Events are ``interesting'' locations in the source code, corresponding
to the beginning or end of evaluation of ``interesting''
sub-expressions. Events are the unit of single-stepping (stepping goes
to the next or previous event encountered in the program execution).
Also, breakpoints can only be set at events. Thus, events play the
role of line numbers in debuggers for conventional languages.<BR>
<BR>
During program execution, a counter is incremented at each event
encountered. The value of this counter is referred as the <EM>current
time</EM>. Thanks to reverse execution, it is possible to jump back and
forth to any time of the execution.<BR>
<BR>
Here is where the debugger events (written ) are located in
the source code:
<UL>
<LI>
Following a function application:
<PRE>
(f arg)
</PRE>
<LI>On entrance to a function:
<PRE>
fun x y z -> ...
</PRE>
<LI>On each case of a pattern-matching definition (function,
<TT>match</TT>...<TT>with</TT> construct, <TT>try</TT>...<TT>with</TT> construct):
<PRE>
function pat1 -> expr1
| ...
| patN -> exprN
</PRE>
<LI>Between subexpressions of a sequence:
<PRE>
expr1; expr2; ...; exprN
</PRE>
<LI>In the two branches of a conditional expression:
<PRE>
if cond then expr1 else expr2
</PRE>
<LI>At the beginning of each iteration of a loop:
<PRE>
while cond do body done
for i = a to b do body done
</PRE>
</UL>
Exceptions: A function application followed by a function return is replaced
by the compiler by a jump (tail-call optimization). In this case, no
event is put after the function application.
<BR>
<BR>
<H3>13.4.2 Starting the debugged program</H3>The debugger starts executing the debugged program only when needed.
This allows setting breapoints or assigning debugger variables before
execution starts. There are several ways to start execution:
<DL COMPACT=compact>
<DT>
<TT>run</TT><DD> Run the program until a breakpoint is hit, or the program
terminates.
<DT><TT>step 0</TT><DD> Load the program and stop on the first event.
<DT><TT>goto </TT><I>time</I><DD> Load the program and execute it until the
given time. Useful when you already know approximately at what time
the problem appears. Also useful to set breakpoints on function values
that have not been computed at time 0 (see section <A HREF="manual026.html#s:breakpoints">13.5</A>).
</DL>The execution of a program is affected by certain information it
receives when the debugger starts it, such as the command-line
arguments to the program and its working directory. The debugger
provides commands to specify this information (<TT>set arguments</TT> and <TT>cd</TT>).
These commands must be used before program execution starts. If you try
to change the arguments or the working directory after starting your
program, the debugger will kill the program (after asking for confirmation).<BR>
<BR>
<H3>13.4.3 Running the program</H3>The following commands execute the program forward or backward,
starting at the current time. The execution will stop either when
specified by the command or when a breakpoint is encountered.<BR>
<BR>
<DL COMPACT=compact>
<DT>
<TT>run</TT><DD> Execute the program forward from current time. Stops at
next breakpoint or when the program terminates.
<DT><TT>reverse</TT><DD> Execute the program backward from current time.
Mostly useful to go to the last breakpoint encountered before the
current time.
<DT><TT>step </TT>[<I>count</I>]<DD> Run the program and stop at the next event. With
an argument, do it <I>count</I> times.
<DT><TT>backstep </TT>[<I>count</I>]<DD> Run the program backward and stop at
the previous event. With an argument, do it <I>count</I> times.
<DT><TT>next </TT>[<I>count</I>]<DD> Run the program and stop at the next
event, skipping over function calls. With an argument, do it
<I>count</I> times.
<DT><TT>previous </TT>[<I>count</I>]<DD> Run the program backward and stop at
the previous event, skipping over function calls. With an argument, do
it <I>count</I> times.
<DT><TT>finish</TT><DD> Run the program until the current function returns.
<DT><TT>start</TT><DD> Run the program backward and stop at the first event
before the current function invocation.
</DL>
<H3>13.4.4 Time travel</H3>You can jump directly to a given time, without stopping on
breakpoints, using the <TT>goto</TT> command.<BR>
<BR>
As you move through the program, the debugger maintains an history of
the successive times you stop at. The <TT>last</TT> command can be used to
revisit these times: each <TT>last</TT> command moves one step back through
the history. That is useful mainly to undo commands such as <TT>step</TT>
and <TT>next</TT>.<BR>
<BR>
<DL COMPACT=compact>
<DT>
<TT>goto </TT><I>time</I><DD>
Jump to the given time.
<DT><TT>last </TT>[<I>count</I>]<DD>
Go back to the latest time recorded in the execution history. With an
argument, do it <I>count</I> times.
<DT><TT>set history </TT><I>size</I><DD>
Set the size of the execution history.
</DL>
<H3>13.4.5 Killing the program</H3><DL COMPACT=compact>
<DT>
<TT>kill</TT><DD> Kill the program being executed. This command is mainly
useful if you wish to recompile the program without leaving the debugger.
</DL>
<H2>13.5 Breakpoints</H2> <A NAME="s:breakpoints"></A>A breakpoint causes the program to stop whenever a certain point in
the program is reached. It can be set in several ways using the
<TT>break</TT> command. Breakpoints are assigned numbers when set, for
further reference. The most comfortable way to set breakpoints is
through the Emacs interface (see section <A HREF="manual026.html#s:inf-debugger">13.10</A>).<BR>
<BR>
<DL COMPACT=compact>
<DT>
<TT>break</TT><DD>
Set a breakpoint at the current position in the program execution. The
current position must be on an event (i.e., neither at the beginning,
nor at the end of the program).<BR>
<BR>
<DT><TT>break </TT><I>function</I><DD>
Set a breakpoint at the beginning of <I>function</I>. This works only
when the functional value of the identifier <I>function</I> has been
computed and assigned to the identifier. Hence this command cannot be
used at the very beginning of the program execution, when all
identifiers are still undefined; use <TT>goto</TT> <I>time</I> to advance
execution until the functional value is available.<BR>
<BR>
<DT><TT>break @</TT> [<I>module</I>] <I>line</I><DD>
Set a breakpoint in module <I>module</I> (or in the current module if
<I>module</I> is not given), at the first event of line <I>line</I>.<BR>
<BR>
<DT><TT>break @</TT> [<I>module</I>] <I>line</I> <I>column</I><DD>
Set a breakpoint in module <I>module</I> (or in the current module if
<I>module</I> is not given), at the event closest to line <I>line</I>,
column <I>column</I>.<BR>
<BR>
<DT><TT>break @</TT> [<I>module</I>] <TT>#</TT> <I>character</I><DD>
Set a breakpoint in module <I>module</I> at the event closest to
character number <I>character</I>.<BR>
<BR>
<DT><TT>break </TT><I>address</I><DD>
Set a breakpoint at the code address <I>address</I>.<BR>
<BR>
<DT><TT>delete </TT>[<I>breakpoint-numbers</I>]<DD>
Delete the specified breakpoints. Without argument, all breakpoints
are deleted (after asking for confirmation).<BR>
<BR>
<DT><TT>info breakpoints</TT><DD> Print the list of all breakpoints.
</DL>
<H2>13.6 The call stack</H2>Each time the program performs a function application, it saves the
location of the application (the return address) in a block of data
called a stack frame. The frame also contains the local variables of
the caller function. All the frames are allocated in a region of
memory called the call stack. The command <TT>backtrace</TT> (or <TT>bt</TT>)
displays parts of the call stack.<BR>
<BR>
At any time, one of the stack frames is ``selected'' by the debugger; several
debugger commands refer implicitly to the selected frame. In particular,
whenever you ask the debugger for the value of a local variable, the
value is found in the selected frame. The commands <TT>frame</TT>, <TT>up</TT> and <TT>down</TT>
select whichever frame you are interested in.<BR>
<BR>
When the program stops, the debugger automatically selects the
currently executing frame and describes it briefly as the <TT>frame</TT>
command does.<BR>
<BR>
<DL COMPACT=compact>
<DT>
<TT>frame</TT><DD>
Describe the currently selected stack frame.<BR>
<BR>
<DT><TT>frame</TT> <I>frame-number</I><DD>
Select a stack frame by number and describe it. The frame currently
executing when the program stopped has number 0; its caller has number
1; and so on up the call stack.<BR>
<BR>
<DT><TT>backtrace </TT>[<I>count</I>], <TT>bt </TT>[<I>count</I>]<DD>
Print the call stack. This is useful to see which sequence of function
calls led to the currently executing frame. With a positive argument,
print only the innermost <I>count</I> frames.
With a negative argument, print only the outermost -<I>count</I> frames.<BR>
<BR>
<DT><TT>up</TT> [<I>count</I>]<DD>
Select and display the stack frame just ``above'' the selected frame,
that is, the frame that called the selected frame. An argument says how
many frames to go up.<BR>
<BR>
<DT><TT>down </TT>[<I>count</I>]<DD>
Select and display the stack frame just ``below'' the selected frame,
that is, the frame that was called by the selected frame. An argument
says how many frames to go down.
</DL>
<H2>13.7 Examining variable values</H2>The debugger can print the current value of simple expressions. The
expressions can involve program variables: all the identifiers that
are in scope at the selected program point can be accessed.<BR>
<BR>
Expressions that can be printed are a subset of Objective Caml
expressions, as described by the following grammar:
<DIV ALIGN=center>
<TABLE CELLSPACING=2 CELLPADDING=0>
<TR><TD ALIGN=right NOWRAP>
<TT><I><FONT COLOR=maroon>expr</FONT></I></TT></TD>
<TD ALIGN=right NOWRAP>::=</TD>
<TD ALIGN=left NOWRAP>
<TT><I><FONT COLOR=maroon>lowercase-ident</FONT></I></TT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP> </TD>
<TD ALIGN=right NOWRAP>|</TD>
<TD ALIGN=left NOWRAP> { <TT><I><FONT COLOR=maroon>capitalized-ident</FONT></I></TT> <TT><FONT COLOR=blue>.</FONT></TT> } <TT><I><FONT COLOR=maroon>lowercase-ident</FONT></I></TT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP> </TD>
<TD ALIGN=right NOWRAP>|</TD>
<TD ALIGN=left NOWRAP> <TT><FONT COLOR=blue>*</FONT></TT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP> </TD>
<TD ALIGN=right NOWRAP>|</TD>
<TD ALIGN=left NOWRAP> <TT><FONT COLOR=blue>$</FONT></TT> <TT><I><FONT COLOR=maroon>integer</FONT></I></TT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP> </TD>
<TD ALIGN=right NOWRAP>|</TD>
<TD ALIGN=left NOWRAP> <TT><I><FONT COLOR=maroon>expr</FONT></I></TT> <TT><FONT COLOR=blue>.</FONT></TT> <TT><I><FONT COLOR=maroon>lowercase-ident</FONT></I></TT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP> </TD>
<TD ALIGN=right NOWRAP>|</TD>
<TD ALIGN=left NOWRAP> <TT><I><FONT COLOR=maroon>expr</FONT></I></TT> <TT><FONT COLOR=blue>.(</FONT></TT> <TT><I><FONT COLOR=maroon>integer</FONT></I></TT> <TT><FONT COLOR=blue>)</FONT></TT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP> </TD>
<TD ALIGN=right NOWRAP>|</TD>
<TD ALIGN=left NOWRAP> <TT><I><FONT COLOR=maroon>expr</FONT></I></TT> <TT><FONT COLOR=blue>.[</FONT></TT> <TT><I><FONT COLOR=maroon>integer</FONT></I></TT> <TT><FONT COLOR=blue>]</FONT></TT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP> </TD>
<TD ALIGN=right NOWRAP>|</TD>
<TD ALIGN=left NOWRAP> <TT><FONT COLOR=blue>!</FONT></TT> <TT><I><FONT COLOR=maroon>expr</FONT></I></TT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP> </TD>
<TD ALIGN=right NOWRAP>|</TD>
<TD ALIGN=left NOWRAP> <TT><FONT COLOR=blue>(</FONT></TT> <TT><I><FONT COLOR=maroon>expr</FONT></I></TT> <TT><FONT COLOR=blue>)</FONT></TT></TD>
</TR></TABLE></DIV>
The first two cases refer to a value identifier, either unqualified or
qualified by the path to the structure that define it.
<TT>*</TT> refers to the result just computed (typically, the value of a
function application), and is valid only if the selected event is an
``after'' event (typically, a function application).
<TT><FONT COLOR=blue>$</FONT></TT> <TT><I><FONT COLOR=maroon>integer</FONT></I></TT> refer to a previously printed value. The remaining four
forms select part of an expression: respectively, a record field, an
array element, a string element, and the current contents of a
reference.<BR>
<BR>
<DL COMPACT=compact>
<DT>
<TT>print </TT><I>variables</I><DD>
Print the values of the given variables. <TT>print</TT> can be abbreviated as
<TT>p</TT>.
<DT><TT>display </TT><I>variables</I><DD>
Same as <TT>print</TT>, but limit the depth of printing to 1. Useful to
browse large data structures without printing them in full.
<TT>display</TT> can be abbreviated as <TT>d</TT>.
</DL>When printing a complex expression, a name of the form <TT>$</TT><I>integer</I>
is automatically assigned to its value. Such names are also assigned
to parts of the value that cannot be printed because the maximal
printing depth is exceeded. Named values can be printed later on
with the commands <TT>p $</TT><I>integer</I> or <TT>d $</TT><I>integer</I>.
Named values are valid only as long as the program is stopped. They
are forgotten as soon as the program resumes execution.<BR>
<BR>
<DL COMPACT=compact>
<DT>
<TT>set print</TT><TT>_</TT><TT>depth</TT> <I>d</I><DD>
Limit the printing of values to a maximal depth of <I>d</I>.
<DT><TT>set print</TT><TT>_</TT><TT>length</TT> <I>l</I><DD>
Limit the printing of values to at most <I>l</I> nodes printed.
</DL>
<H2>13.8 Controlling the debugger</H2>
<H3>13.8.1 Setting the program name and arguments</H3><DL COMPACT=compact>
<DT>
<TT>set program</TT> <I>file</I><DD>
Set the program name to <I>file</I>.
<DT><TT>set arguments</TT> <I>arguments</I><DD>
Give <I>arguments</I> as command-line arguments for the program.
</DL>A shell is used to pass the arguments to the debugged program. You can
therefore use wildcards, shell variables, and file redirections inside
the arguments. To debug programs that read from standard input, it is
recommended to redirect their input from a file (using
<TT>set arguments < input-file</TT>), otherwise input to the program and
input to the debugger are not properly separated, and inputs are not
properly replayed when running the program backwards.<BR>
<BR>
<H3>13.8.2 How programs are loaded</H3>The <TT>loadingmode</TT> variable controls how the program is executed.<BR>
<BR>
<DL COMPACT=compact>
<DT>
<TT>set loadingmode direct</TT><DD>
The program is run directly by the debugger. This is the default mode.
<DT><TT>set loadingmode runtime</TT><DD>
The debugger execute the Objective Caml runtime <TT>camlrun</TT> on the program.
Rarely useful; moreover it prevents the debugging of programs compiled
in ``custom runtime'' mode.
<DT><TT>set loadingmode manual</TT><DD>
The user starts manually the program, when asked by the debugger.
Allows remote debugging (see section <A HREF="manual026.html#s:communication">13.8.6</A>).
</DL>
<H3>13.8.3 Search path for files</H3>The debugger searches for source files and compiled interface files in
a list of directories, the search path. The search path initially
contains the current directory <TT>.</TT> and the standard library directory.
The <TT>directory</TT> command adds directories to the path.<BR>
<BR>
Whenever the search path is modified, the debugger will clear any
information it may have cached about the files.<BR>
<BR>
<DL COMPACT=compact>
<DT>
<TT>directory</TT> <I>directorynames</I><DD>
Add the given directories to the search path. These directories are
added at the front, and will therefore be searched first.<BR>
<BR>
<DT><TT>directory</TT><DD>
Reset the search path. This requires confirmation.
</DL>
<H3>13.8.4 Working directory</H3>Each time a program is started in the debugger, it inherits its working
directory from the current working directory of the debugger. This
working directory is initially whatever it inherited from its parent
process (typically the shell), but you can specify a new working
directory in the debugger with the <TT>cd</TT> command or the <TT>-cd</TT>
command-line option.<BR>
<BR>
<DL COMPACT=compact>
<DT>
<TT>cd</TT> <I>directory</I><DD>
Set the working directory for <TT>camldebug</TT> to <I>directory</I>.<BR>
<BR>
<DT><TT>pwd</TT><DD>
Print the working directory for <TT>camldebug</TT>.
</DL>
<H3>13.8.5 Turning reverse execution on and off</H3>In some cases, you may want to turn reverse execution off. This speeds
up the program execution, and is also sometimes useful for interactive
programs. <BR>
<BR>
Normally, the debugger takes checkpoints of the program state from
time to time. That is, it makes a copy of the current state of the
program (using the Unix system call <TT>fork</TT>). If the variable
<I>checkpoints</I> is set to <TT>off</TT>, the debugger will not take any
checkpoints.<BR>
<BR>
<DL COMPACT=compact>
<DT>
<TT>set checkpoints</TT> <I>on/off</I><DD>
Select whether the debugger makes checkpoints or not.
</DL>
<H3>13.8.6 Communication between the debugger and the program</H3>
<A NAME="s:communication"></A>The debugger communicate with the program being debugged through a
Unix socket. You may need to change the socket name, for example if
you need to run the debugger on a machine and your program on another.<BR>
<BR>
<DL COMPACT=compact>
<DT>
<TT>set socket</TT> <I>socket</I><DD>
Use <I>socket</I> for communication with the program. <I>socket</I> can be
either a file name, or an Internet port specification
<I>host</I>:<I>port</I>, where <I>host</I> is a host name or an Internet
address in dot notation, and <I>port</I> is a port number on the host.
</DL>On the debugged program side, the socket name is passed either by the
<TT>-D</TT> command line option to <TT>camlrun</TT>, or through the
<TT>CAML</TT><TT>_</TT><TT>DEBUG</TT><TT>_</TT><TT>SOCKET</TT> environment variable.<BR>
<BR>
<H3>13.8.7 Fine-tuning the debugger</H3> <A NAME="s:fine-tuning"></A>Several variables enables to fine-tune the debugger. Reasonable
defaults are provided, and you should normally not have to change them.<BR>
<BR>
<DL COMPACT=compact>
<DT>
<TT>set processcount</TT> <I>count</I><DD>
Set the maximum number of checkpoints to <I>count</I>. More checkpoints
facilitate going far back in time, but use more memory and create more
Unix processes.
</DL>As checkpointing is quite expensive, it must not be done too often. On
the other hand, backward execution is faster when checkpoints are
taken more often. In particular, backward single-stepping is more
responsive when many checkpoints have been taken just before the
current time. To fine-tune the checkpointing strategy, the debugger
does not take checkpoints at the same frequency for long displacements
(e.g. <TT>run</TT>) and small ones (e.g. <TT>step</TT>). The two variables <TT>bigstep</TT>
and <TT>smallstep</TT> contain the number of events between two checkpoints
in each case.<BR>
<BR>
<DL COMPACT=compact>
<DT>
<TT>set bigstep</TT> <I>count</I><DD>
Set the number of events between two checkpoints for long displacements.
<DT><TT>set smallstep</TT> <I>count</I><DD>
Set the number of events between two checkpoints for small
displacements.
</DL>The following commands display information on checkpoints and events:<BR>
<BR>
<DL COMPACT=compact>
<DT>
<TT>info checkpoints</TT><DD>
Print a list of checkpoints.
<DT><TT>info events</TT> [<I>module</I>]<DD>
Print the list of events in the given module (the current module, by default).
</DL>
<H3>13.8.8 User-defined printers</H3>Just as in the toplevel system (section <A HREF="manual021.html#s:toplevel-directives">8.2</A>),
the user can register functions for printing values of certain types.
For technical reasons, the debugger cannot call printing functions
that reside in the program being debugged. The code for the printing
functions must therefore be loaded explicitly in the debugger.<BR>
<BR>
<DL COMPACT=compact>
<DT>
<TT>load</TT><TT>_</TT><TT>printer "</TT><I>file-name</I><TT>"</TT><DD>
Load in the debugger the indicated <TT>.cmo</TT> or <TT>.cma</TT> object file. The
file is loaded in an environment consisting only of the Objective Caml
standard library plus the definitions provided by object files
previously loaded using <TT>load</TT><TT>_</TT><TT>printer</TT>. If this file depends on other
object files not yet loaded, the debugger automatically loads them if
it is able to find them in the search path. The loaded file does not
have direct access to the modules of the program being debugged.<BR>
<BR>
<DT><TT>install</TT><TT>_</TT><TT>printer </TT><I>printer-name</I><DD>
Register the function named <I>printer-name</I> (a
value path) as a printer for objects whose types match the argument
type of the function. That is, the debugger will call
<I>printer-name</I> when it has such an object to print.
The printing function <I>printer-name</I> must use the <TT>Format</TT> library
module to produce its output, otherwise its output will not be
correctly located in the values printed by the toplevel loop.<BR>
<BR>
The value path <I>printer-name</I> must refer to one of the functions
defined by the object files loaded using <TT>load</TT><TT>_</TT><TT>printer</TT>. It cannot
reference the functions of the program being debugged.<BR>
<BR>
<DT><TT>remove</TT><TT>_</TT><TT>printer </TT><I>printer-name</I><DD>
Remove the named function from the table of value printers.
</DL>
<H2>13.9 Miscellaneous commands</H2><DL COMPACT=compact>
<DT>
<TT>list</TT> [<I>module</I>] [<I>beginning</I>] [<I>end</I>]<DD>
List the source of module <I>module</I>, from line number
<I>beginning</I> to line number <I>end</I>. By default, 20 lines of the
current module are displayed, starting 10 lines before the current
position.
<DT><TT>source</TT> <I>filename</I><DD>
Read debugger commands from the script <I>filename</I>.
</DL>
<H2>13.10 Running the debugger under Emacs</H2> <A NAME="s:inf-debugger"></A>The most user-friendly way to use the debugger is to run it under Emacs.
See the file <TT>emacs/README</TT> in the distribution for information on how
to load the Emacs Lisp files for Caml support.<BR>
<BR>
The Caml debugger is started under Emacs by the command <TT>M-x camldebug</TT>, with argument the name of the executable file
<I>progname</I> to debug. Communication with the debugger takes place
in an Emacs buffer named <TT>*camldebug-</TT><I>progname</I><TT>*</TT>. The editing
and history facilities of Shell mode are available for interacting
with the debugger.<BR>
<BR>
In addition, Emacs displays the source files containing the current
event (the current position in the program execution) and highlights
the location of the event. This display is updated synchronously with
the debugger action.<BR>
<BR>
The following bindings for the most common debugger commands are
available in the <TT>*camldebug-</TT><I>progname</I><TT>*</TT> buffer:<BR>
<BR>
<DL COMPACT=compact>
<DT>
<TT>C-c C-s</TT><DD> (command <TT>step</TT>): execute the program one step forward.
<DT><TT>C-c C-k</TT><DD> (command <TT>backstep</TT>): execute the program one step backward.
<DT><TT>C-c C-n</TT><DD> (command <TT>next</TT>): execute the program one step
forward, skipping over function calls.
<DT>Middle mouse button<DD> (command <TT>display</TT>): display named value.
<TT>$</TT><I>n</I> under mouse cursor (support incremental browsing of large
data structures).
<DT><TT>C-c C-p</TT><DD> (command <TT>print</TT>): print value of identifier at point.
<DT><TT>C-c C-d</TT><DD> (command <TT>display</TT>): display value of identifier at point.
<DT><TT>C-c C-r</TT><DD> (command <TT>run</TT>): execute the program forward to next
breakpoint.
<DT><TT>C-c C-v</TT><DD> (command <TT>reverse</TT>): execute the program backward to
latest breakpoint.
<DT><TT>C-c C-l</TT><DD> (command <TT>last</TT>): go back one step in the command history.
<DT><TT>C-c C-t</TT><DD> (command <TT>backtrace</TT>): display backtrace of function calls.
<DT><TT>C-c C-f</TT><DD> (command <TT>finish</TT>): run forward till the current
function returns.
<DT><TT>C-c <</TT><DD> (command <TT>up</TT>): select the stack frame below the
current frame.
<DT><TT>C-c ></TT><DD> (command <TT>down</TT>): select the stack frame above the
current frame.
</DL>In all buffers in Caml editing mode, the following debugger commands
are also available:<BR>
<BR>
<DL COMPACT=compact>
<DT>
<TT>C-x C-a C-b</TT><DD> (command <TT>break</TT>): set a breakpoint at event closest
to point
<DT><TT>C-x C-a C-p</TT><DD> (command <TT>print</TT>): print value of identifier at point
<DT><TT>C-x C-a C-d</TT><DD> (command <TT>display</TT>): display value of identifier at point
</DL>
<HR>
<A HREF="manual025.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="manual027.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
<A HREF="index.html"><IMG SRC ="contents_motif.gif" ALT="Contents"></A>
</BODY>
</HTML>
|