home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 1 / crawlyvol1.bin / program / compiler / szadb21b / doc / lpr / primer.txt < prev    next >
Text File  |  1992-01-14  |  51KB  |  1,462 lines

  1.  
  2.  
  3.  
  4.  
  5.                             szadb primer
  6.  
  7.  
  8.  
  9.                           Michal Jaegermann
  10.  
  11.  
  12.  
  13.                              edited by
  14.  
  15.                            Anthony Howe
  16.  
  17.  
  18.                          14 January 1992
  19.  
  20.  
  21.  
  22.  
  23.  (this line printer approximation produced by dvi2tty and slightly edited)
  24.  
  25.  
  26.  
  27.  
  28. There is NO WARRANTY with respect to this publication, or the
  29. program it describes, and disclaim any implied or explicit suggestions
  30. of usefulness for any particular purpose.  Use this program only if
  31. you are willing to assume all risks, and damages, if any, arising as a
  32. result, even if caused by negligence or other fault.
  33.  
  34.  
  35.  
  36. Sozobon C compiler and szadb debugger are both copyright (c)1989,1992
  37. by Sozobon Ltd. Both can be freely copied and distributed provided
  38. all copyright notices will remain intact and all modified versions will
  39. be clearly marked as such.
  40.  
  41.  
  42. Atari, ST, TOS and GEMDOS are trademarks of Atari Co.
  43. GEM is a trademark of Digital Research Co.
  44. Mark Williams C is a trademark or Mark Williams Co.
  45. Unix is a trademark of AT&T.
  46.  
  47.  
  48.  
  49.  
  50. 1   Introduction
  51.  
  52.  
  53. szadb is an assembly level debugger for programs written for
  54. the TOS operating system on the Atari ST computer.  It is
  55. primarily meant to be a companion to the freely distributed
  56. Sozobon C compiler, and can be copied and passed around under
  57. the same conditions.
  58. One of design goals of the original szadb project was to
  59. provide a debugger closely resembling adb, which is available
  60. on most Unix systems.  There are some dissimilarities which
  61. follow mostly from differences in target machines and
  62. operating systems.  Still users with an adb experience should
  63. feel right at home.
  64. The originally released version 1.0 was written by Johann
  65. Ruegg and Don Dugger.  Expanded to version 1.2 in a joint
  66. effort of Anthony Howe and Michal Jaegermann.  Further
  67. development to version 1.4 by Michal Jaegermann.  A document
  68. describing version 1.2 was prepared by Anthony Howe and
  69. Michal Jaegermann.  Modified slightly by the last author to
  70. reflect changes in versions 1.3, 1.4 and 2.1
  71. This manual does not describe versions of szadb as they were
  72. released as parts of Sozobon C compiler packages, but rather
  73. modified relatives which are not products of Sozobon team and
  74. which provide richer and more flexible user interface for a
  75. price of an increased demand on computer resources.
  76. Version 1.2 introduced multi-command input lines, which could
  77. be attached to breakpoints and stepping commands.  Other it
  78. features included recording of a debugging sesion in a file,
  79. definitions function keys, and other assorted niceties.  In
  80. addition to original Sozobon C symbols (Alcyon C style, also a
  81. default for ST version of gcc compiler) it also accepted the
  82. symbol table formats from Mark Williams C.
  83. Version 1.3, not very widely distributed, added to this list a
  84. "GST extension" of a symbol table format, with symbols up to
  85. twenty two characters long.  Executables with such tables are
  86. produced by newer versions of gcc (ST) loader with -G option
  87. to the compiler.
  88. Version 1.4 expanded a range of supported screen displays.  In
  89. particular it is possible now to run szadb in all six TT
  90.  
  91.  
  92.  
  93.                                  1
  94.  
  95.  
  96.  
  97.  
  98. resolutions.  Moniterm, in a tandem with a standard ST
  99. monitor, also can be used in a particularly convenient manner.
  100. If you have some graphic card which disallows switching of a
  101. screen base check if Moniterm remarks will not apply to your
  102. situation.
  103. Version 2.1 added a support for "SozobonX" symbol table
  104. format which showed up in version 2.0 of Sozobon C compiler.
  105. If your compiler's symbol table format is not supported, or
  106. there are other changes or additions you wish to add, the
  107. complete source is provided free with the debugger.  For
  108. symbol tables check file adb1.c, a function setsym() and a
  109. family.
  110. The document you are reading now serves as a gentle
  111. introduction to "adb way of debugging".  It gives expanded
  112. explanations and examples but it does not cover all points
  113. described in a formal szadb description.  Read the other
  114. document in any case!
  115.  
  116.  
  117.  
  118. 2   First steps
  119.  
  120.  
  121. 2.1   Starting
  122.  
  123.  
  124. It is possible to run szadb either from a desktop or from a
  125. text shell, in either low, medium or high resolution.  In this
  126. tutorial we will assume that szadb was launched from a command
  127. line on a screen 80 characters wide (this setting affects only
  128. the layout of some displays) and that the executable is called
  129. adb.ttp, in tribute to its older brother.
  130. The simplest way of starting szadb is to type something
  131. similar to
  132.  
  133.  
  134.      adb.ttp program.ext
  135.  
  136.  
  137. where program.ext is any executable.  Note that the file
  138. extension (tos, ttp,prg) must be provided.  For debugging
  139. purposes, it is preferable to compile your program with
  140. debugger information (symbol tables).  For Sozobon pass the
  141. option -t to either cc or ld.  It is possible to debug a
  142. program without this information but this is not a trivial
  143.  
  144.  
  145.  
  146.                                  2
  147.  
  148.  
  149.  
  150.  
  151. task.  This tutorial assumes that symbolic information is
  152. provided.
  153. For debugging purposes, it is much preferable not to strip off
  154. symbol tables.  In this tutorial we will always assume that
  155. this was not done.  To achieve that effect, while compiling
  156. with Sozobon C, pass -t flag to cc.
  157. If you do not have your favourite test program handy then you
  158. may compile from the provided sources and use for experiments
  159. a simplified version of unexpand.tos; it replaces, if
  160. possible, runs of white space from stdin with tabs and writes
  161. results on stdout.  Further examples will use that program
  162. compiled by Sozobon C compiler, version 1.2, with -t and -O
  163. flags.
  164. Once the debugger is started you should see on your screen a
  165. display resembling the following:
  166.  
  167.  
  168.      Szadb version 2.1mj(english)
  169.      >
  170.  
  171.  
  172. indicating that everything is in order.  The character > is
  173. the prompt.  Its presence is the most striking visual feature
  174. showing that we are not dealing with the "real" adb.
  175.  
  176.  
  177.  
  178. 2.2   Where am I?
  179.  
  180.  
  181. If you hit at this moment <Return> key szadb should respond
  182. with
  183.  
  184.  
  185.      __start:
  186.  
  187.  
  188. The debugger positioned itself at the very beginning of a
  189. loaded program.  szadb "remebers" the last command and its
  190. current location, which is known as "dot".  You may set
  191. "dot" by typing any valid expression which will evaluate to
  192. an address.  Hitting <Return> by itself repeats the last typed
  193. in command (not the executed one!  This distinction will be
  194. important later).
  195. In this version the "dot" is set to low TPA, or a starting
  196. execution address.  The initial default command is /a which
  197. will print the symbolic value of "dot" followed by a colon.
  198. To see a numerical display of the "dot" try the following:
  199.  
  200.  
  201.  
  202.                                  3
  203.  
  204.  
  205.  
  206.  
  207.      .=X <Return>
  208.  
  209.  
  210. for a hexadecimal address, or
  211.  
  212.  
  213.      .=D <Return>
  214.  
  215.  
  216. for the same one in a decimal form.
  217. A note for Unix hackers.  In szadb there is no distinction
  218. objectspace and dataspace.  Therefore prefixes ?  and / in
  219. commands are equivalent.  Typing ?a will cause the same effect
  220. as typing /a.
  221. Addresses are printed in a form symbol+offset, where possible.
  222. If there is no symbol table, or if offset is getting too big,
  223. you will notice that addresses are printed as hexadecimal
  224. values.  The offset limit has initialy value of 0x400 but it
  225. can be changed by $s request, in the form
  226.  
  227.  
  228.      $s <new_value>
  229.  
  230.  
  231. The default number base for commands and displays is sixteen
  232. (hexadecimal).  Please refer to the documentation on how to
  233. change the default base and use numbers in other bases.
  234. White space, which is not a part of a literal string, is not
  235. significant in szadb requests as long as a total number of
  236. characters in the command line is below an input buffer length
  237. (78 for this version).  <Return> always terminates a current
  238. line.  Try adding some blanks and tabs to previously typed
  239. commands.
  240.  
  241.  
  242.  
  243. 2.3   Disassembling
  244.  
  245.  
  246. Lets try something more exciting.  A request for printing
  247. machine language instructons is /i.  It may be preceded by a
  248. count.  Try ,4/i.  The comma is necessary and informs szadb
  249. that what follows is a number of times to repeat the request.
  250. If you will omit it then the debugger will decide that you
  251. want to start with a location 4.  If all is well then szadb
  252. will respond
  253.  
  254.  
  255.  
  256.  
  257.                                  4
  258.  
  259.  
  260.       __start:
  261.                            move.l   sp,a5
  262.                            move.l   4(sp),a4
  263.                            move.l   a4,__base
  264.                            move.l   8(a4),d3
  265.  
  266.  
  267.  
  268.  After this request a default command becomes /i.  Therefore
  269. to see the next four locations it is enough to type ,4 and
  270. szadb will show
  271.  
  272.       > ,4
  273.       __start+10:
  274.                            add.l    c(a4),d3
  275.                            move.l   d3,_etext
  276.                            move.l   10(a4),d3
  277.                            add.l    14(a4),d3
  278.  
  279.  
  280.  
  281. Note that the "dot" has moved.  This is a common feature of
  282. all memory examining requests.  The "dot" will be set past
  283. all already scanned memory.  If you want to look at the same
  284. memory area one more time, possibly using a different request,
  285. use & to reset your position.  It is a shorthand for the last
  286. typed in address.
  287.  
  288.  
  289.  
  290. 2.4   More on talking to szadb
  291.  
  292.  
  293. A general szadb command has a form
  294.  
  295.  
  296.      address ,count request_with_its_modifiers
  297.  
  298.  
  299. where each of three parts is optional or possibly not used.
  300. Please refer to the documentation to see all available
  301. requests.  For all practical purposes count 1 means forever.
  302. Read a little bit further before trying this.
  303. Display format modifiers can be concatenated together.  For
  304. example, the following
  305.  
  306.  
  307.      main,9/ai
  308.  
  309.  
  310. will print the first nine instructions, labelled by their
  311. addresses, starting from _main.  Like this:
  312.  
  313.       _main:               link      a6,#-6
  314.       _main+4:             movem.l  [d3-5],-(sp)
  315.  
  316.  
  317.  
  318.                                  5
  319.  
  320.  
  321.  
  322.  
  323.       _main+8:             move.l   #_tabs,-(sp)
  324.       _main+e:             bsr       _settab
  325.       _main+12:            addq.w   #4,sp
  326.       _main+14:            clr.w    d5
  327.       _main+16:            clr.w    d3
  328.       _main+18:            move.l   #__iob,-(sp)
  329.       _main+1e:            jsr       _fgetc
  330.  
  331.  Note that the leading underscore, required to produce an
  332. internal form of a symbol main was prepended automatically.
  333. To get to an address of __main, if such symbol in your program
  334. exists, you have to type its name in full.  Similar but
  335. slightly different rules will be in force if your program has
  336. a symbol table in the MWC format.
  337. If you do not know which symbols are available issue a request
  338. $e.  A display similar to the following will start to scroll
  339. accross your screen.
  340.  
  341.       > $e
  342.       __start: 77812
  343.       __exit: 778da
  344.       _gemdos: 778e2
  345.       _bios: 778ec
  346.       _xbios: 778f6
  347.       _bdos: 77900
  348.       _main: 77954
  349.       _settab: 77a72
  350.       __main: 77aac
  351.       _exit: 77b0c
  352.       ................
  353.  
  354.  The general method to stop a scrolling screen for a moment is
  355. to use <^S> and any other key will continue.  A <^C> will
  356. cancel the command and any further output.  Starting with
  357. version 1.4 this includes also a paging.  This means that
  358. display stops after showing one screenful of symbols and szadb
  359. waits for your keyboard input.  Keys <q>, <Q> and <^C> break,
  360. any other key continues.  A processing of the request is
  361. finished when you will get back a standard szadb prompt of
  362. "> ".
  363.  
  364.  
  365.  
  366.                                  6
  367.  
  368.  
  369.  
  370.  
  371. Some hexadecimal numbers may look like symbols.  For example,
  372. if you happen to have a symbol abba in your program then szadb
  373. will understand main+abba as a request for setting the "dot"
  374. to an address which is a sum of addresses of main and abba,
  375. even if you really meant an adress at offset of 0xabba from
  376. main.  To avoid this misinterpretation it is enough to type
  377. main+0abba - number has a leading zero.  It the symbol
  378. abba is not defined then the ambiguity does not arise.
  379. Assuming that the default base is sixteen abba will be taken
  380. as a number.  Otherwise such expression will be not accepted
  381. and you will see only an error message.  The form 0xabba has a
  382. unique meaning and always works.
  383.  
  384.  
  385.  
  386. 3   Running under szadb
  387.  
  388.  
  389. 3.1   How to run - with arguments
  390.  
  391.  
  392. To run a loaded program, with a name passed as a szadb
  393. argument, one has to type :c, which is a short for :continue.
  394. When the program is running szadb switches to the program
  395. screen which is different from that one used by the debugger.
  396. In particular, all program keyboard input will be accepted
  397. from the program screen.  Unfortunately there is no way, at
  398. least not in this version, to read the debugged program
  399. standard input from a file.  It has to be typed in.  To switch
  400. from the szadb screen the program window use <^W> and return
  401. from the visit with any other character.
  402. The program itself may have arguments.  In principle there are
  403. two methods with which they can be set.  Firstly, you may
  404. specify them when starting szadb.  Everything which follows
  405. the name of a loaded executable will be taken as its arguments
  406. and copied verbatim to its basepage.  A request $p will
  407. display the whole basepage and it will allow you to check if
  408. you really got what you expected.  szadb does not allow for
  409. any argument extending schemes and it will trunctate command
  410. lines which are too long.
  411. The second method allows you to specify arguments as an
  412. optional tail of :c request.  Once arguments were set, by any
  413. of these methods, they cannot be changed and further attempts
  414. to do so will be ignored.
  415.  
  416.  
  417.                                  7
  418.  
  419.  
  420.  
  421.  
  422. Since both shell command lines and the input line inside of
  423. szadb are limited in length, and partially already taken, it
  424. may appear that there is no way to fill all available basepage
  425. space with program arguments by any method, short of writing
  426. directly to a computer memory.  As we will see later this is
  427. not true, even if it requires a little bit of trickery.  (See
  428. further descriptions how to define and execute function keys.)
  429. When you are ready to quit, because you are done or lost and
  430. wish to start afresh, enter $q.  If the debugee process exited
  431. of its own accord then szadb will terminate too.
  432.  
  433.  
  434.  
  435. 3.2   Setting breakpoints
  436.  
  437.  
  438. Executing a program under a debugger is of no great use
  439. without breakpoints.  Here is the simplest way in which they
  440. can be set.
  441.  
  442.  
  443.      main:b
  444.  
  445.  
  446. We can do even better than that.  Try
  447.  
  448.  
  449.      main:b ="My first szadb breakpoint"n;.=XD;,8/ai
  450.  
  451.  
  452. Everything which follows :b on the input line will be stored
  453. and executed later on when the breakpoint is hit.  Multiple
  454. commands are separated by semicolons.  By the way, you may use
  455. semi-colons for immediate requests too.
  456. Breakpoints also can have counts.  Using as an example
  457. unexpand.tos, and a fragment of its disassembled code shown in
  458. a previous section, we may set a breakpoint
  459.  
  460.  
  461.      main+18,3:b="about to read"n
  462.  
  463.  
  464. in a main loop of this program, just before fgetc() is called.
  465. With this count an execution will stop only for every third
  466. character to be accepted.
  467. Setting a breakpoint on the top of an existing one is allowed
  468. and it will simply cause a replacement - changing possibly a
  469. count and commands to execute.  A list of all current
  470. breakpoints, with their counts and associated commands, is
  471.  
  472.  
  473.  
  474.                                  8
  475.  
  476.  
  477.  
  478.  
  479. produced by the $b request.  Information shown at the bottom
  480. of this list will be explained later.
  481. It is not the best idea to set a breakpoint somewhere between
  482. two program instructions.  Nothing terrible will happen
  483. immediately, but your debugging run may end up prematurely
  484. amid an utter confusion.  Sometimes it is possible to restart
  485. a wayward program by writing a needed address directly into a
  486. program counter with a address>pc request, but this is not
  487. guaranteed to work.  It is also advisable to keep breakpoints
  488. on an execution path.  They are a limited resource and there
  489. is no point wasting it.
  490.  
  491.  
  492.  
  493. 3.3   Displaying information
  494.  
  495.  
  496. szadb provides many ways to display information about the
  497. state of your program.  Some of these requests were detailed
  498. above.  Another is $r, which will show the contents of all
  499. registers and status flags.  If you are interested in an
  500. individual register then use something like
  501.  
  502.  
  503.      <a0=X
  504.  
  505.  
  506. Replacing above = with /, or ?, will bring a hexadecimal
  507. display of the long word stored at the location pointed to by
  508. register a0.  Careful here, the last form will move the
  509. "dot".  There are many other possible formats.  Try, for
  510. example, main,20/x  and <b,2/s .
  511. The second example uses one of four read-only variables
  512. provided by szadb, which are
  513.  
  514.  
  515.      l        lowest text address
  516.      t        length of the text segment
  517.      b        start of the bbs segment
  518.      d        length of the data segment
  519.  
  520.  
  521. With an exception of l names follow the Unix convention.  They
  522. will be particulary handy if you will have a misfortune of
  523. debugging executable without a symbol table.
  524. Formats in requests can be combined.  Let us try something
  525. like follows.
  526.  
  527.  
  528.  
  529.                                  9
  530.  
  531.  
  532.  
  533.  
  534.      ="Text memory dump"2n;main,<b-main%8+1/4x4^rr|rr8cn
  535.  
  536.  
  537. and here are initial lines of a resulting display, where "."
  538. replaces all non-printable characters.
  539.  
  540.       Text memory dump
  541.  
  542.  
  543.       _main:
  544.              4e56       fffa       48e7       1c00  |  NV..H...
  545.              2f3c          6       8ae6       6100  |  /<....a.
  546.               10e       584f       4245       4243  |  ..XOBEBC
  547.              2f3c          6       88a0       4eb9  |  /<....N.
  548.                 6       7c40       584f       3800  |  ..|@XO8.
  549.              b87c       ffff       6706       b87c  |  .|..g..|
  550.                 4       6612       4267       4eb9  |  ..f.BgN.
  551.                 6       77d6       544f       4cdf  |  ..w.TOL.
  552.  
  553.  
  554.  
  555.  Note that division is denoted by a % character and that 8
  556. divides a difference <b-main and not only main, since all
  557. expressions are evaluated in strict left-to-right order.
  558. Let's break down the format modifiers to see what is actually
  559. happening
  560.  
  561.  
  562.      4x        print four short words in hex,
  563.      4^        backup the "dot" by four current fields (short words),
  564.      rr|rr     print 2 blanks, vertical bar, and 2 more blanks,
  565.      8c        print 8 characters,
  566.      n         and a newline.
  567.  
  568.  
  569. Displays that are wider then a current screen width (40 or 80)
  570. will have lines split automatically.
  571.  
  572.  
  573.  
  574. 3.4   Recording your session
  575.  
  576.  
  577. A request $>filename starts writing a transcript of everything
  578. which shows on your screen to the file filename.  All examples
  579. longer than a couple of lines were prepared this way.  If the
  580. filename is missing then the currently opened transcript will
  581.  
  582.  
  583.  
  584.                                 10
  585.  
  586.  
  587.  
  588.  
  589. be closed.  The output is always appended to the given file,
  590. so that it is possible to open, close, and re-open the same
  591. file any number of times.
  592. Because GEMDOS is not re-entrant it is not a very very good
  593. idea to perform an actual file write while processing a GEMDOS
  594. call.  It is nearly certain you will crash your system.  The
  595. safest course in such spots is to turn recording temporarily
  596. off.  However, transcript output is buffered by default, so
  597. actual writes occur only when the buffer is flushed when full
  598. or because the file was closed.  Therefore with proper care,
  599. one can empty the buffer prior to dangerous spots and even
  600. create a record of a GEMDOS call, provided it is not too
  601. wordy.  A handy definition for a function key to do this is
  602. $>;$> (see the last section on function keys).
  603. It is advisable not to write files to your hard drive, instead
  604. use a RAM drive or a dedicated floppy (which can be
  605. reformatted in case of disaster).  Remember that a buggy
  606. program and the debugger can write anywhere.  Over system file
  607. buffers and cached File Allocation Tables as well.
  608. If you need all memory you can get it is possible to turn off
  609. transcript buffering with command line option -nb.  But then
  610. you will have to be extremely careful about possible conflicts
  611. with GEMDOS.
  612. Note!  After $>file request your default command is $> and not
  613. the last command you were executing previously.  It is
  614. possible to execute $> inadvertently by hitting <Return> or by
  615. making some mistake while typing the next line.  This will
  616. close your transcript with obvious results.  When something
  617. like thats happens, or when in doubt, issue another $>file.
  618.  
  619.  
  620.  
  621. 4   Bug hunting
  622.  
  623.  
  624. 4.1   Compiling for szadb
  625.  
  626.  
  627. Lets have a closer look at the C program below.  Its stated
  628. purpose is to replace, if possible, runs of white space with
  629. tabs.  The width of a tab is fixed and equal to a constant
  630. TABSTOP. If a text line is getting too long then substitutions
  631.  
  632.  
  633.  
  634.                                 11
  635.  
  636.  
  637.  
  638.  
  639. are abandoned and remaining characters are copied without
  640. modifications.
  641.  
  642.  
  643.       #include <stdio.h>
  644.  
  645.  
  646.       #define MAXLIN 132
  647.       #define TABSTOP 8
  648.     5
  649.       int                 tabs[MAXLIN];
  650.  
  651.  
  652.       main ()
  653.       {
  654.    10     int             c, delay, col;
  655.           void            settab ();
  656.  
  657.  
  658.           settab (tabs);
  659.  
  660.  
  661.    15     col = delay = 0;
  662.           while (EOF != (c = getchar ())) {
  663.                if (MAXLIN < col) {
  664.                    /* copy remaining characters on a line */
  665.                    do {
  666.    20                  putchar (c);
  667.                    } while ('\n' != c &&
  668.                                    EOF != (c = getchar ()));
  669.                    col = 0;
  670.                }
  671.    25          else {
  672.                    switch (c) {
  673.                    case '\t':
  674.                        while (!tabs[col])
  675.                            col++;
  676.    30              case ' ':            /* fallthrough */
  677.                        if (!tabs[col]) {
  678.                            col += 1;
  679.                            continue;   /* keep delay */
  680.                        }
  681.    35                  putchar ((delay == col) ? ' ' : '\t');
  682.                        col += 1;
  683.  
  684.  
  685.  
  686.                                 12
  687.  
  688.  
  689.  
  690.  
  691.                        break;
  692.                    default:
  693.                        while (delay < col) {
  694.    40                      putchar (' ');
  695.                            delay += 1;
  696.                        }
  697.                        putchar (c);
  698.                        col = ('\n' == c ? 0 : col + 1);
  699.    45                  break;
  700.                    } /* switch */
  701.                } /* if (MAXLIN < col) */
  702.                delay = col;
  703.           }
  704.    50     exit (0);
  705.       }
  706.  
  707.  
  708.       void
  709.       settab (tab_pt)
  710.    55 short            *tab_pt;
  711.       {
  712.           int              i;
  713.  
  714.  
  715.           for (i = 0; i < MAXLIN; i++) {
  716.    60          *tab_pt++ = (0 == (i % TABSTOP));
  717.           }
  718.       }
  719.  
  720.  
  721. This program has actually two bugs.  See if you can find them
  722. just examinig the source.
  723. Here is how szadb can help.  Compile source as follows (these
  724. commands are for Sozobon C)
  725.  
  726.  
  727.      cc -t -O -o unexpand.tos unexpand.c
  728.  
  729.  
  730. Flag -O is not necessary but with this particular compiler you
  731. will probably find a disassembled code easier to follow.  You
  732. may test the compiled executable on its own source.
  733.  
  734.  
  735.      unexpand.tos <unexpand.c >output
  736.  
  737.  
  738.  
  739.                                 13
  740.  
  741.  
  742.  
  743.  
  744. In the first moment the program appears to work, but a closer
  745. examination of the output reveals that the indentation is not
  746. exactly right.  Moreover, some lines start with a blank,
  747. followed by a tab, which is not really what was intended.
  748. There are also other problems.  Check yourself.  The likely
  749. suspect will be an array tabs of tabstops filled by a function
  750. settab().
  751.  
  752.  
  753.  
  754. 4.2   The first bug
  755.  
  756.  
  757. Start the program under szadb control
  758.  
  759.  
  760.      adb.ttp unexpand.tos
  761.  
  762.  
  763. and set a breakpoint at settab+4, just after link instruction.
  764. Run the program with :c ; $C. This will produce the following
  765. display
  766.  
  767.       break at _settab+4
  768.       _settab+4:           movem.l  [d3-4],-(sp)
  769.       _settab+4(0006,8bb4)
  770.       _main+12(0001,0006,8cbe,0006,73a2)
  771.       __main+4e(? at 69cc6)
  772.  
  773.  In the absence of better information all arguments shown in
  774. the stack backtrace are assumed to be two bytes wide.  We know
  775. from the source that settab() actualy expects one pointer.
  776. Confirm that it got a right one by putting it together from
  777. two halfs and using the request 68bb4=p to print it as the
  778. symbol.  You should see _tabs in response.  To continue
  779. execution of the current function till it returns to its
  780. caller, use :f which stands for :finish.
  781. It is clear from lines 30 and 35 that the first tabstop in
  782. _tabs is expected to be on a position TABSTOP - 1 .  Dumping
  783. some initial fragment of the just initialized array we see the
  784. following:
  785.  
  786.       > tabs,3/4x
  787.       _tabs:
  788.                 1          0          0          0
  789.                 0          0          0          0
  790.                 1          0          0          0
  791.  
  792.  
  793.  
  794.                                 14
  795.  
  796.  
  797.  
  798.  
  799.  This is clearly wrong and one bug becomes obvious.  To repair
  800. it line 59 should be changed to
  801.  
  802.      for (i = 1; i <= MAXLIN; i++) {...}
  803.  
  804.  
  805.  
  806. 4.3   ...and the other one
  807.  
  808.  
  809. The second bug is harder to spot, since for most of test
  810. inputs our program will work correctly.  This is a typical
  811. example of a program broken for boundary conditions.  To make
  812. it easier to track the problem set MAXLIN to some small
  813. integer (around 10 should be good), recompile the program,
  814. restart the debugging session and set a breakpoint at main+28,
  815. just after a character was read.  Set this breakpoint with a
  816. count and a request to show a received character with
  817.  
  818.      main+28,5:b <d0=cx
  819.  
  820. With carefuly chosen input this will show where you are in the
  821. program and will skip unnecessary stops in the same time.  You
  822. have to provide an input by typing it yourself.  Remember that
  823. to repeat the last command :c it is enough to hit <Return>.
  824. For execution defaults szadb will use the most recently typed
  825. command even if some other requests were executed by
  826. breakpoints.
  827. In order to see how the received character is processed you
  828. can single step with :s, which will follow program execution.
  829. The request :n will single step like :s but will execute
  830. function calls at full speed and so have the effect of
  831. stepping over them.  Breakpoints set on skipped levels still
  832. will be obeyed.
  833. Tracing some tests inputs with the value of the variable col
  834. around MAXLIN should reveal the second error soon enough.  If
  835. you want to try it yourself, do not read further.
  836. Looking at line 17 we find a sharp less-than inequality in the
  837. test.  It should be replaced by a less-than-equal-to.
  838. Otherwise, when the value of col equals MAXLIN, and your input
  839. is "right", the program is trying to read, in lines 28 and 31,
  840. from the location &tabs[col], which is one past the end of the
  841. array.  The remaining analysis of this bug is left as an
  842. exercise to the reader.
  843.  
  844.  
  845.  
  846.                                 15
  847.  
  848.  
  849.  
  850.  
  851. 4.4   Breaking out
  852.  
  853.  
  854. Another stepping command is the :j jump request.  Its purpose
  855. it to short-circuit loops.  It behaves exactly like :n in that
  856. it skips-over function calls but unlike the :n request which
  857. follows branch instructions, the :j will place a temporary
  858. breakpoint at the instruction immediately following the
  859. current instruction in memory.  Think of :n as
  860. step-next-logical instruction and :j as step-next-physical
  861. instruction.  The idea is that you only use :j to step-out of
  862. loops where you are sitting on the loop-back branch.
  863.  
  864.               ...
  865.               bra      .test
  866.       .body:
  867.               ...
  868.       .test:
  869.               cmp      d0, d1
  870.               bnz      .body
  871.       .end
  872.               ...
  873.  
  874.  In the example above, if you are sitting on the bnz
  875. instruction and you wish to execute the remainder of the loop
  876. at full speed then you use the :j, which places a temporary
  877. breakpoint at the location .end.  However care must be taken
  878. when using this command because it is possible that the
  879. flow-of-control never reaches the temporary breakpoint.
  880.  
  881.                ...
  882.                bra      .snert
  883.       .never:
  884.                ...                ; might be local data here
  885.       .snert:
  886.                rts
  887.  
  888.  This is a case where NOT to use the :j command.  Basically to
  889. use the :j request you should know how your C compiler sets up
  890. its loops or where your assembler code is meant to go.  It is
  891. sometime a good idea to put a safety breakpoint somewhere you
  892. know you will end up.
  893.  
  894.  
  895.  
  896.                                 16
  897.  
  898.  
  899.  
  900.  
  901. Because of the unusual nature of the :j request, it will not
  902. autorepeat if the next command is just a <Return> key.  Instead
  903. :n is performed.  Also it is also considered a variant of :n
  904. when attaching execution requests to stepping commands (see
  905. further down).
  906. It should be also mentioned that all stepping commands have
  907. upper case counterparts, which are noisier.  When used they
  908. return the a full register display after the step (:S is like
  909. doing :s;$r).
  910.  
  911.  
  912.  
  913. 5   More fun and games
  914.  
  915.  
  916. This section covers some finer points of szadb use.  You may
  917. put them aside when just starting first experiments with the
  918. debugger.  But probably one day you will find some of that
  919. information very useful.
  920.  
  921.  
  922.  
  923. 5.1   Advanced steps
  924.  
  925.  
  926. It was already mentioned that all stepping commands may have
  927. also attached szadb requests.  As a matter of fact there is
  928. even one default, for :f.  To get a similar effect for other
  929. steps just type what you want to be executed after a given
  930. command on the szadb input line.  For example
  931.  
  932.  
  933.      :s ="this string printed by :s command"n
  934.  
  935.  
  936. You will notice that this form of :step does not move you
  937. ahead in the program.  This gives an opportunity to set and
  938. modify requests in advance, without an immediate execution.
  939. It also saves your nerves if you are not a very good typist.
  940. To really step by one instruction forward hit <Return> and
  941. observe what will happen.  As noted before :j is a variant of
  942. :n and setting request for it will really change what is
  943. attached to :n.
  944. The example above is not tremendously useful, but tracking
  945. values of a chosen registers can be.  Or anything else that
  946. you need and that will fit on the command line.  This
  947. condition is much less limiting than it appears when used in
  948. conjunction with function keys.
  949.  
  950.  
  951.  
  952.                                 17
  953.  
  954.  
  955.  
  956.  
  957. There are two points to remember.  There is no syntax check
  958. while you are setting requests.  Watch what you are typing if
  959. you do not want to see only error messages.  And there is
  960. nothing to prevent a direct or indirect recursion.  Since a
  961. depth of szadb stack is limited and <^C> does not always work
  962. it is better to avoid such constructs.
  963. If you came to a conclusion that the only way to change
  964. requests attached to a stepping command is to overtype them
  965. with something else then you are correct.  Moreover an empty
  966. string is not a good replacement since it causes an execution.
  967. Luckily there is some other way to turn a noise off.  Try
  968. typing ::s- and similar commands for :n and :f.  Switched off
  969. requests are not gone, unless later redefined.  They can be
  970. brought back by a similar command as above in which - was
  971. replaced with +.  The default request for :f is special.  It
  972. cannot be overtyped or turned on by ::f+.  To bring it back
  973. use ::f` instead.
  974. There is one more way of request switching.  If you will type,
  975. for example, ::n_, then whatever was attached to :s will be
  976. performed also for :n, instead of a "native" command.  This
  977. gives an opportunity to create, say, a quite complicated
  978. request for :n and most of the time execute a simpler request
  979. for :s.  When an original request for :n is needed it is
  980. enough to type ::n+ to get it back.  The same mechanism works
  981. for :f, temporarily redirecting its requests "down" to the
  982. first active one.  There is no similar switching going the
  983. other way.  To gain a better understanding try all of this
  984. after defining various requests for each of stepping commands
  985. and examine effects with the $b command after every switch.
  986. It is also possible to make user breakpoint silent or not.
  987. For example
  988.  
  989.  
  990.      main:b ="entering main"
  991.  
  992.  
  993. main::b- and main::b+ turns the action off and on.
  994.  
  995.  
  996.  
  997. 5.2   How to use function keys
  998.  
  999.  
  1000. Function keys can be defined, only once per debugging session,
  1001. by reading their definitions from a file.  The name of the
  1002.  
  1003.  
  1004.  
  1005.                                 18
  1006.  
  1007.  
  1008.  
  1009.  
  1010. file can be passed on the command line with -k filename.  The
  1011. file may be as simple as this
  1012.  
  1013.       # flush buffers of a transcript file record
  1014.       F1 $>;$>record
  1015.  
  1016.  
  1017.       F2 ="this is pretty long string which will be ins\
  1018.       erted when you will hit function key F2"n;
  1019.       F1 ="an attempt to redefine F1\n"
  1020.  
  1021.  Note that an uppercase F, which starts key definition, has to
  1022. be in the first column and it has to be immediately followed
  1023. by a valid key number.  Shifed functions keys have numbers
  1024. between 11 and 20.  A definition of <F2> is continued on the
  1025. next line since a terminating newline is escaped with a \
  1026. character.  Otherwise this continuation line would be simply
  1027. ignored.  szadb also does not pay any attention to the second
  1028. definition of <F1>.  To see a list of all function keys defined
  1029. type $k.
  1030. Defined function keys can be used in two ways.  Just hitting a
  1031. function key will insert into the current input line as many
  1032. characters from a corresponding string as it will fit.  The
  1033. resulting input text can be edited.  In order to execute a
  1034. full definition use $k followed by a key number - always in
  1035. decimal.  For example, a request $k2 will print twice the
  1036. message, which was just defined in the function key file.
  1037. Note that there no way to specify that a function key should
  1038. execute immediately instead of waiting for a <return>.  Also is
  1039. there no default function key file name like - adb.key -
  1040. so you'll have to specify the -k file option on the command line
  1041. each time or use a command alias.  Note also that requests of
  1042. a form $k<number> do not autorepeat.
  1043. It is clear that strings of commands attached to function keys
  1044. can be longer than a lenght of the input line.  Actually
  1045. around 2K will be accepted.  This is hopefuly longer than any
  1046. szadb script you ever want to write.  Especially if you take
  1047. into account that one script can call another.  Warnings
  1048. against recursion apply as well.
  1049. Such long scripts can be, of course, attached to breakpoints
  1050. or stepping commands.  They give also, previously mentioned,
  1051.  
  1052.  
  1053.  
  1054.                                 19
  1055.  
  1056.  
  1057.  
  1058.  
  1059. opportunity to fill all available space on a base page with
  1060. command line arguments.  Just define one of function keys as
  1061.  
  1062.  
  1063.      :c <text to put on a base page>
  1064.  
  1065.  
  1066. and execute at the beggining of your session.  Coupled with a
  1067. possibility of directly modifying the memory this allows for a
  1068. preparation of scripts which will emulate any extended
  1069. arguments scheme, even if szadb directly does not support
  1070. directly any of these.
  1071.  
  1072.  
  1073.  
  1074. 5.3   Other symbol table formats
  1075.  
  1076.  
  1077. This debugger was designed as a companion for Sozobon C and
  1078. therefore it understands its symbol table format, which was
  1079. inherited from Alcyon compiler.  Starting with version 2.0 of
  1080. Sozobon C compiler a new format - "SozobonX" - was
  1081. introduced and which allows for an unlimited length of symbol
  1082. names (there is an internal compiler limit of 80 characters,
  1083. but it can be raised if you really need to do that).  From
  1084. 2.1mj szadb recognizes this format as well.  The version for
  1085. which this document was written also supports MWC -
  1086. currently the official Atari development compiler.  It will
  1087. cooperate also with the ST version of GNU compiler gcc.  If
  1088. you happen to have an older version of gcc loader it may be
  1089. necessary for you to get your hands dirty in a source code.
  1090. Even better idea would be to update your compiler.  The
  1091. current gcc loader can optionally produce symbol tables in
  1092. "GST format" where symbols can be up to twenty two
  1093. characters long.  A support for this format exists in versions
  1094. of szadb 1.3 and up.
  1095.  
  1096.  
  1097.  
  1098. 5.3.1  Mark Williams C support
  1099.  
  1100.  
  1101. Symbols created by MWC are outwardly different from those
  1102. produced by Sozobon C in that that names can be longer - up
  1103. to sixteen characters - and an underscore character is
  1104. appended instead of beeing prepended.  When szadb will detect
  1105. an MWC produced object it will apply its conventions.  That
  1106. means that if you type main it will first try to find a symbol
  1107.  
  1108.  
  1109.  
  1110.                                 20
  1111.  
  1112.  
  1113.  
  1114.  
  1115. main.  If this fails it will search for main_ next (not for
  1116. _main).  If a symbol name has a leading underscore, or more
  1117. than one trailing, you have to type them yourself.
  1118. The debugger is trying to guess by itself which compiler
  1119. produced the current executable.  If it guesses wrong you may
  1120. always override its choice by dropping a hint on the command
  1121. line.  It consists of an -os flag for the Sozobon format and
  1122. -om for MWC. Remember that if you work in an assembler the
  1123. guessing code can always be fooled.  The flags always provide
  1124. a way to set things straight.
  1125. When writing this guessing code I had no official description
  1126. of the format used by MWC. All necessary information was
  1127. inferred from an examination of MWC produced binaries.  The
  1128. code worked so far on everything I tried, but it may happen to
  1129. be wrong for your version.  Since szadb comes complete with
  1130. source you can modify it accordingly and recompile (look for
  1131. all places where a global variable swidth is modified).
  1132.  
  1133.  
  1134.  
  1135. 5.3.2  How to work with gcc
  1136.  
  1137.  
  1138. (Some of an information in this section is likely to be of a
  1139. historical value only.  On the other hand maybe there are
  1140. still some stray copies of an old gcc loader still in use.
  1141. Who knows?)
  1142. A default form of executables created by this compiler is with
  1143. a symbol table attached.  You need to use -s flag if you
  1144. really do not want it produced.  A default format for TOS
  1145. version of this compiler is basically the same as for Sozobon
  1146. C or Alcyon.  If you happen to be an owner of an old version
  1147. there is one subtle difference.  A bit which carries an
  1148. information that a symbol is global one, known as S_EXT in
  1149. szadb parlance, is not set.  This makes the debugger blind to
  1150. a symbol presence.
  1151. Here are instructions how to modify an old version of a file
  1152. ld.c which contains sources for gcc linker.  In a function
  1153. write_atari_sym(p, str) for TOS version add the following
  1154.  
  1155.  
  1156.       if (p->n_type & N_EXT)
  1157.               sym.a_type |= A_GLOBL;
  1158.  
  1159.  
  1160.  
  1161.                                 21
  1162.  
  1163.  
  1164.  
  1165.  
  1166. just before a line which reads
  1167.  
  1168.  
  1169.       sym.a_value = p->n_value;
  1170.  
  1171.  
  1172. Recompile and reinstall linker and from this moment on szadb
  1173. recognizes gcc produced symbols.
  1174. Even better idea would be to upgrade your compiler to a newer
  1175. version.  The modification described above will be already
  1176. present, but there is more.  Currently gcc, upon a presence of
  1177. -G flag, may produce symbol tables with names up to twenty two
  1178. characters long.  Versions 1.3 and up of szadb will correctly
  1179. recognize such symbols making for much nicer debugging (even
  1180. if this will require more typing from time to time).
  1181. Internally this is a version of Sozobon format.  Use -os flag
  1182. in case of confusion.
  1183. If for some reasons you cannot upgrade, you do not have linker
  1184. sources or you cannot recompile them - because you do not
  1185. have enough memory, for example - not everyting is lost.  It
  1186. is quite feasible to disable S_EXT check in setsym() (look in
  1187. the file adb1.c).  You will not notice any change for Sozobon
  1188. C created executables.  All symbols occuring in their symbol
  1189. tables are actually always global.  This is not quite true for
  1190. gcc and some new, sometimes strange, symbols will appear but
  1191. usually this will not create any problems.  In order to have
  1192. only globals in a gcc produced symbol table pass -x flag
  1193. either to gcc or to its linker.
  1194.  
  1195.  
  1196.  
  1197. 5.3.3  Command line interpretation
  1198.  
  1199.  
  1200. As mentioned before szadb supports only "vanilla" command
  1201. line without any extension schemes.  Other compilers, like
  1202. gcc, may expect something different and there could be some
  1203. disagreements about an interpretation of a command line.
  1204. Usually this can be fixed quite easily.  Here is a file, named
  1205. fixargs.adb, which can be used with a command line following
  1206. this pattern
  1207.  
  1208.  
  1209.       szadb.ttp -k fixargs.adb <program> [argument, ...]
  1210.  
  1211.  
  1212. where <program> was compiled by gcc.
  1213.  
  1214.  
  1215.  
  1216.                                 22
  1217.  
  1218.  
  1219.  
  1220.  
  1221.       # an example of a function keys definition file used
  1222.       # to correct an argument interpretation for gcc
  1223.       # compiled program
  1224.       F1  $k11; $k13 ; $k14; $k15; $b; :c
  1225.       F11 main:b <sp,10/x; $k12
  1226.       F12 <sp/W *(<sp+4)-3; <sp+4/W *(<sp+8)+c; <sp,10/x
  1227.       # for 16 bit
  1228.       #F12 <sp/w *(<sp+2)-3; <sp+2/W *(<sp+6)+c; <sp,10/x
  1229.       F13 getitime:b
  1230.  
  1231.  This file defines some function keys.  The fact that commands
  1232. associated with keys <F14> and <F15> do not exist, even if they
  1233. are referenced in a line for <F1>, is not harmful in any way.
  1234. You may define these keys later for your advantage.  After
  1235. szadb started hit <F1> followed by <Return>.  This will cause,
  1236. among others, an execution of a command attached to <F11>, i.e
  1237. <F1-shifted>.  This command will set a breakpoint at a start of
  1238. real program with a fixup command attached.  In turn, this
  1239. will modify your stack causing your program to see proper
  1240. arguments.  Requests in a form of <sp,10/x are added only for
  1241. reassurance and to show what really happens.
  1242. The example above assumes that a symbol getitime is defined in
  1243. your program.  Replace with something which is really present
  1244. or you will see some error messages.  They are not fatal.  All
  1245. of this is not going to work if main is not present in your
  1246. symbol table.  This is not really likely for a program which
  1247. has a symbol table and was compiled from C sources, but may
  1248. happen for other languages.  Modify accordingly.
  1249.  
  1250.  
  1251.  
  1252. 5.3.4  Other compilers
  1253.  
  1254.  
  1255. If you own a compiler which produces symbolic information in
  1256. an unsupported format you can modify szadb yourself to support
  1257. it.  For a model of how to do this look for setsym() and
  1258. mwsetsym() in the file adb1.c.  Both of them call addsym()
  1259. which performs an actual insertion of a new symbol and its
  1260. value into a linked list of supported symbols.  A current
  1261. version of addsym() will handle symbol names of any length but
  1262. internally they will be chopped off to something not longer
  1263.  
  1264.  
  1265.  
  1266.                                 23
  1267.  
  1268.  
  1269.  
  1270.  
  1271. than the current value of the global variable swidth.  Ensure
  1272. that this value is set properly for your needs.
  1273. The mechanism above can be easily extended to allow reading
  1274. some symbols and their values from a user suplied text file.
  1275. Some may find it very handy.  The current version of szadb
  1276. does not support this feature.  It is possible to roll your
  1277. own if you really need it.
  1278.  
  1279.  
  1280.  
  1281. 5.3.5  Screens of not a standard ST size
  1282.  
  1283.  
  1284. Starting with a version 1.4 szadb does not have standard ST
  1285. screen parameters embedded into its code.  Instead it reads
  1286. all necessary information from line-A variables and reserves
  1287. all needed buffers accordingly.  In particular it follows that
  1288. szadb will run correctly in all six TT resolutions.  It may
  1289. also work with different overscan utilities, provided screen
  1290. geometry variables in a machine were updated properly.  Note
  1291. that fonts used are resolution dependent but fixed for a given
  1292. resolution.  This means that putting monochrome ST into 50
  1293. line mode will not give nice results without code
  1294. modifications (see w_init() in window.c).
  1295. A special support is provided for Moniterm monitors.  Because
  1296. of limitations of a Moniterm driver you will need also a
  1297. standard ST monitor connected in parallel.  In such setup your
  1298. program screen will be displayed on Moniterm and szadb will
  1299. print its information to a side monitor; no screen flipping
  1300. with <^W> is needed or possible.
  1301. Since the debugger tries to limit use of a dynamic memory
  1302. allocations the code which reserves szadb work screen and
  1303. necessary buffers does that in a "false" program space and
  1304. is located in start.s.  Should you decide to modify it for any
  1305. reasons look for comments which attempt to describe what
  1306. really happens.
  1307. Note:  despite of the fact that szadb can be used on TT the
  1308. version 2:1 is still ST debugger in that sense that it does not
  1309. support yet any of 68020/30 specific codes.  This should be
  1310. fine for most programs in the nearest future.  An expansion
  1311. will be easy and straightforward provided you will have
  1312. necessary reference handy.
  1313.  
  1314.  
  1315.  
  1316.                                 24
  1317.  
  1318.  
  1319.  
  1320.  
  1321. 5.4   Customization
  1322.  
  1323.  
  1324. Some possible customizations were already mentioned.  The
  1325. other obvious one is a version of szadb without on-line help.
  1326. If you feel brave enough remove the definition of the compile
  1327. time constant HELP from the makefile.  A size of the
  1328. executables will undoubtely go down.
  1329. In order to create a version in some other language edit a
  1330. file lang.h.  It contains all messages which szadb may
  1331. display.
  1332. You can adjust to your taste some other points.  For example,
  1333. what are default requests attached to stepping commands and
  1334. what is their status (look in stepping.c for bpstat(),
  1335. findcmds(), bpt_list[]).  Which characters are used for
  1336. requests switching (see getrequs() in pcs.c).  Some features,
  1337. like support for functions keys or other symbol table formats,
  1338. can be taken out easily without affecting the whole design.
  1339. If you try to recreate szadb with another compiler you should
  1340. note that essential parts of this program were written in
  1341. assembler and may have to be translated to something your
  1342. tools can accept.  Here is another point to watch for.  A
  1343. variable _BLKSIZ sets size of Malloc'ed blocks.  If a library
  1344. you use supports something similar modify accordingly.  There
  1345. are also some constructs in C code, like a static
  1346. initialization of a union member (bpt_list in stepping.c) and
  1347. an array of size 0 in a definition of struct symbol in adb.h,
  1348. which are accepted by Szozobon C but can give a hiccup to some
  1349. other compilers.  These points can be modified without undue
  1350. strain.  Otherwise the code should be pretty portable,
  1351. although it is ST specific by its very nature.
  1352.  
  1353.  
  1354.  
  1355. 5.5   Running on a verge
  1356.  
  1357.  
  1358. You may find yourself in a situation when your program wants
  1359. all memory it can get and together with the debugger does not
  1360. exactly fits into available space.  There are still some
  1361. things which can be done.
  1362. Keep in mind that szadb grabs all memory it needs before a
  1363. program to debug is loaded and it does not make any claims
  1364.  
  1365.  
  1366.  
  1367.                                 25
  1368.  
  1369.  
  1370.  
  1371.  
  1372. later.  These requirements can be minimized.  Function key
  1373. definitions if non-existent will not use memory at all,
  1374. discounting the supporting code.  This code by itself is
  1375. mostly contained in a file fkeydefs.c and it is easy to
  1376. remove.  The flag -nc, for no commands, gives some memory for
  1377. a price of missing breakpoint requests.  A more substantial
  1378. memory chunk can be released with -nb, for no buffering on
  1379. transcript, flag.  You still can open a transcript file but
  1380. all output will be direct.  Beware of GEMDOS when using
  1381. transcripts without buffering.
  1382. If this does not help then there is a time to trim some fat
  1383. from szadb itself.  You will have to recompile it leaving some
  1384. features out.  On-line help is probably the first candidate.
  1385. All this effort can be wasted if you will forget about one
  1386. thing.  Due to an infamous design bug in TOS a Malloc system
  1387. call can be invoked only a small fixed number of times.  When
  1388. this pool is exhausted you will get "out of memory
  1389. condition" even if memory is still plentiful.  Therefore all
  1390. allocation functions, from smart libraries, request a memory
  1391. from the system in bigger pieces and later try to satisfy all
  1392. requests chopping from an already owned resource.  The name of
  1393. the game for szadb is to use for all its needs only one chunk
  1394. of a system memory which is just big enough, so not too much
  1395. of an unused memory will be left.  The whole symbol table of a
  1396. debugged program must fit there and all szadb requests for a
  1397. space for internal structures have to be statisfied.  To
  1398. adjust sizes properly you may want to change a constant CHUNK
  1399. which is defined at the top of a file adb.c.
  1400. If everything else fail you may still try to change a value of
  1401. a global variable __STKSIZ from start.s but this would be
  1402. probably the last stand.
  1403.  
  1404.  
  1405.  
  1406. 5.6   Writing to memory
  1407.  
  1408.  
  1409. It can be done.  This is left as an exercise to the reader.
  1410. Check your documentation.
  1411.  
  1412.  
  1413.  
  1414.                                 26
  1415.  
  1416.  
  1417.  
  1418.  
  1419. Contents
  1420.  
  1421.  
  1422. 1  Introduction                                                    1
  1423.  
  1424.  
  1425. 2  First steps                                                     2
  1426.    2.1  Starting  . . . . . . . . . . . . . . . . . . . . . . . .  2
  1427.    2.2  Where am I? . . . . . . . . . . . . . . . . . . . . . . .  3
  1428.    2.3  Disassembling . . . . . . . . . . . . . . . . . . . . . .  4
  1429.    2.4  More on talking to szadb  . . . . . . . . . . . . . . . .  5
  1430.  
  1431.  
  1432. 3  Running under szadb                                             7
  1433.    3.1  How to run - with arguments   . . . . . . . . . . . . . .  7
  1434.    3.2  Setting breakpoints . . . . . . . . . . . . . . . . . . .  8
  1435.    3.3  Displaying information  . . . . . . . . . . . . . . . . .  9
  1436.    3.4  Recording your session  . . . . . . . . . . . . . . . . . 10
  1437.  
  1438.  
  1439. 4  Bug hunting                                                     11
  1440.    4.1  Compiling for szadb  . . . . . . . . . . . . . . . . . . . 11
  1441.    4.2  The first bug  . . . . . . . . . . . . . . . . . . . . . . 14
  1442.    4.3  ...and the other one   . . . . . . . . . . . . . . . . . . 15
  1443.    4.4  Breaking out . . . . . . . . . . . . . . . . . . . . . . . 16
  1444.  
  1445.  
  1446. 5  More fun and games                                              17
  1447.    5.1  Advanced steps . . . . . . . . . . . . . . . . . . . . . . 17
  1448.    5.2  How to use function keys . . . . . . . . . . . . . . . . . 18
  1449.    5.3  Other symbol table formats . . . . . . . . . . . . . . . . 20
  1450.         5.3.1  Mark Williams C support . . . . . . . . . . . . . . 20
  1451.         5.3.2  How to work with gcc  . . . . . . . . . . . . . . . 21
  1452.         5.3.3  Command line interpretation . . . . . . . . . . . . 22
  1453.         5.3.4  Other compilers . . . . . . . . . . . . . . . . . . 23
  1454.         5.3.5  Screens of not a standard ST size . . . . . . . . . 24
  1455.    5.4  Customization  . . . . . . . . . . . . . . . . . . . . . . 25
  1456.    5.5  Running on a verge . . . . . . . . . . . . . . . . . . . . 25
  1457.    5.6  Writing to memory  . . . . . . . . . . . . . . . . . . . . 26
  1458.  
  1459.  
  1460.  
  1461.                                  i
  1462.