update
[fw/sdcc] / debugger / README
1 sdcc/debugger
2
3 SDCDB debugger
4 ======================
5 Notes Feb 10, 2002 - Karl Bongers
6
7 SDCDB is a debugger for SDCC compiler.  It works as a front
8 end to the ucSim simulator/disassembler program.
9
10 WARNING: SDCDB is EXPERIMENTAL and NOT A FULLY FUNCTIONING TOOL.
11
12 SDCDB does hold out promise for a nice debugger tool that
13 could integrate well with ucSim and other SDCC tools.  It has
14 some nice functionality that could augment ucSim nicely.
15 It reads in a lot of symbolic information from the .CDB
16 debug files as well as the source code and assembly
17 listings referred to in these CDB files.
18 This can be used to display your program data, list
19 c or asm source code and set breakpoints.
20
21 Unfortunately, SDCDB is not quite finished and does not
22 function well enough yet to recommend for general use.
23
24
25 Usage Notes
26 ======================
27 Compile with --debug option:
28 sdcc --debug hi.c
29 This should generate .cdb symbolic debug files.
30
31 Load sdcdb, like this:
32 sdcdb hi.ihx
33
34 Then you need to do an initial "run" command.  It should hopefully
35 stop somewhere at the main() entrypoint.
36
37 Now you should be able to list code, and set breakpoints.  Type
38 "c" to continue running to a breakpoint, or type "s" to single
39 step or "n" to skip function calls.  Tpye "help" for a summary
40 of commands.
41
42 Use a preceeding bang("!") to do s51 simulator commands.  So for
43 example:
44 !pc
45 will send the "pc" command to ucSim and
46 give you the program counter and list the current line of assembly.
47 !help
48 will give you the brief command line help listing of ucSim.  But
49 this help will scroll of the screen.  So to get a list, I redirect
50 stdout to a text file to examine like this:
51 sdcdb hi.ihx 2>&1 | tee sdcdb.log
52
53 Type '.' to toggle to a full time ucSim prompt.
54
55
56 SDCDB problem areas.
57 ======================
58
59 Ok, so what are some of its problems?  Lets try to itemize
60 them so we can fix them:
61
62 * It hangs sometimes when trying to do step or next.
63
64    This probably has something to do with the context
65    sdcdb tries to build dynamically.  Sdcdb tries to
66    trace program operation by placing hidden breakpoints
67    and stepping threw the simulation between these.
68
69 * Does not print variables properly.  Seems to use the
70   wrong address for the variable. (fixed)
71
72 * ASM listing not implemented.
73   This should be easy enough to add.  This feature
74   really needs to be implemented before this is a useful
75   tool.  That or addresses of code functions need to be
76   readily available for raw ucSim commands.
77
78 * No way to browse symbols, files names.
79   Preferably, it is easy to learn the addresses of variables
80   and functions too.
81   (working on this... see new ls,lm,lf commands)
82
83 * Does not allow listing, setting breakpoints or viewing variables
84   before starting the simulation.
85   (I am fixing now, partly fixed)
86
87 * p codestr - print on code char * broken, could be CDB info invalid.
88
89
90 Changes Made
91 ======================
92
93 Added a -z option.  Any options after -z on sdcdb invocation line
94  are passed directly to ucSim.
95
96 Fixed print basic variable command(was not parsing or expecting
97   "0x" in data coming from ucSim).  Dump bit command changed from
98   "db" to "dump".
99
100 Add support for the following alternative ucSim binaries:
101  -mz80 - use "uz80" simulator.
102  -mavr - use "uavr" simulator.
103  -mxa - use "uxa" simulator.
104
105   Note that Z80(and probably avr/xa) does not produce enough
106   CDB debugging information to
107   make SDCDB useful.  Hopefully CDB support will be
108   added to these other linkers and code generators.
109
110 Added lf,lm,ls commands(list functions, list modules, list symbols).
111  This allows browsing some the CDB information SDCDB pulls in
112  to do the wonderful things it does.
113
114 Added '.' prefix/command, used alone switches back and forth
115  from ucSim/SDCDB command mode).  Also when at the (ucsim) prompt,
116  if a command is prefixed with '.' it will route the command to
117  the SDCDB command processor.  (This could obsolete the '!' prefix).
118
119
120 ======================
121
122 Fix any remaining shortcomings above and make sdcdb integrate better with
123 ucSim.
124
125 Concerning the hanging on next/step instructions:  This is critical
126 to fix.  I beleive the problem is related to SDCDB's attempt to
127 dynamically track context.  To do this, it sets many temporary break
128 points and uses these to progress step by step through the source code.
129 It does not seem reliable.  It might be an idea to offer a simplified
130 mode of stepping and breakpoints.  Need to study this more.
131
132 Make SDCDB integrate better with ucSim.
133 I think if sdcdb can act more transparently in regard to ucSim
134 it would be used more.  So stress adding value and enhancing
135 ucSim operation, and not block or hide the functionality of ucSim.
136
137 * combine print "p" & "pt" together.  We have room on the screen,
138 might as well print its type, address and value in one command.
139
140 * "fr" command prints the current position in the C code.
141 Should also print the raw code address for dumping ucSim code.
142
143
144
145 Developer Notes:
146 ======================
147 To debug, it might be helpful to turn on verbose debug dumps
148 by uncommenting #define SDCDB_DEBUG in sdcdb.h.
149
150 Some basic layout:
151 sdcdb.c - main shell of the program.
152 cmd.c - process user commands typed in.
153 simi.c - handle talking to the simulator via a socket connection.
154 symtab.c - Misc. functions to translate and process linked list
155   structures(modules, functions, symbols, etc) and CDB file
156   parsing.
157 break.c - track and implement break points.
158
159 Understanding the structures and access mechanisms of SDCDB
160 is a bit of work.  The structures include generic linked list
161 and function access.  These lists are accessed in part by the
162 functions from ../../src/SDCCset.c and SDCChash.c.  See the
163 cmd.c:infoSymbols() routine to gain some insight into these
164 main program structures.  Or type "info symbols" to dump
165 out some of these.  The new ls,lm,lf commands are also based
166 on showing information about these lists of structures.
167
168 Generic functions are used to act on these linked lists of
169 structures.  For example, in cmd.c, DEFSETFUNC(funcWithName)
170 function will find a function structure with a given name.
171 So the linked list of function structures(with the head
172 "functions") is traversed and when one is found with a matching
173 name, a pointer to the function structure is returned.
174
175 The src/SDCCset.c,SDCCset.h contain much of the core helper
176 routines to allowed to implement these linked list access
177 functions.
178
179 The dynamic context tracking is difficult to understand.
180 It has some concept of stack use, as in
181 cmd.c:printSymValue(), where it can print variables relative
182 to the stack pointer.
183