ddd fixes
[fw/sdcc] / debugger / README
1 sdcc/debugger
2
3 SDCDB debugger - Development notes.
4 ======================
5
6
7 Notes April 23, 2003
8 ========================
9 Martin Helmling added support for ddd GUI debugger.
10 Code added to display assembly, set variables, and other commands
11 to interface to ddd.
12
13 From Martins email:
14
15 in the attachment is my actual patch.
16
17 The 'up' and 'down' stack commands are not implemented.
18 But the features for 'ddd' to see bopth the c source and the assembler 
19 works,
20 also the display of variables.
21 Set variables are only implemented for basic types.
22 Register variables can also displayed, but here I think a problem in the 
23 *.cdb file exists.
24 Sometimes the register name not exists:
25
26 S:LcacheTxAnalogValue$offset$1$1({1}SC:U),E,0,0
27 S:LcacheTxAnalogValue$i$1$1({1}SC:S),R,0,0,[]
28 S:LcacheTxAnalogValue$val$1$1({4}ST__00020000:S),E,0,0
29 S:LcacheTxAnalogValue$value$1$1({1}SC:U),R,0,0,[]
30 S:LcacheTxAnalogValue$sloc0$1$0({4}SL:U),E,0,0
31 S:LsetRelays$addr$1$1({1}SC:U),R,0,0,[r2]
32 S:LsetRelays$state$1$1({1}SC:U),R,0,0,[r3]
33 S:LsetRelays$value$1$1({1}SC:U),R,0,0,[r5]
34 S:L_main$i$1$1({1}SC:U),R,0,0,[]
35 S:L_main$j$1$1({1}SC:U),R,0,0,[r3]
36 S:L_main$ok$1$1({1}SC:U),R,0,0,[r3]
37
38 the empty [] I mean !!
39
40 Is this a known bug  in sdcc ?
41
42 Also sometimes not the correct breakpoints for stepping found  in sdcdb. 
43 I try to fix this tomorrow.
44
45 Additional patches and notes from Martin(4-24-03):
46 in the attachment you found three patches:
47 debugpatch: Only for debugging, you can switch on and off the 4 different
48              debug and you can grep the debug by the prefix.
49 signalpatch:Now the simulator stops if the user sends an interrupt
50              ( or 'ddd' ) and also the simulator does not die by another
51              user signal.
52
53 sympatch:   This is not a feature, THIS is the fix of a BUG !!!
54              In some circumstances in the *.cdb file the Symbol record
55              comes before the function record. So the symbol was
56              generated TWO TIMES in the symbol list. The L:G and L:XG 
57
58              records then insert entry and exit address to the wrong
59              symbol. So before a new symbol is generated for the
60              function, a lookup in the symboltable is done.
61
62 Example of a *.cdb:
63
64 S:G$ZpuInitialize$0$0({2}DF,SV:S),C,0,0
65 S:G$ZpuInitialize$0$0({2}DF,SV:S),C,0,0
66 F:G$ZpuInitialize$0$0({2}DF,SV:S),Z,0,0,0,0,0
67 S:LZpuInitialize$i$1$1({2}SI:S),R,0,0,[]
68 L:G$ZpuInitialize$0$0:ADF
69 L:XG$ZpuInitialize$0$0:BBB
70
71
72 Notes Feb 10, 2002 - Karl Bongers
73 ========================
74
75 SDCDB is a debugger for SDCC compiler.  It works as a front
76 end to the ucSim simulator/disassembler program.
77
78 WARNING: SDCDB is EXPERIMENTAL and NOT A FULLY FUNCTIONING TOOL.
79
80 SDCDB does hold out promise for a nice debugger tool that
81 could integrate well with ucSim and other SDCC tools.  It has
82 some nice functionality that could augment ucSim nicely.
83 It reads in a lot of symbolic information from the .CDB
84 debug files as well as the source code and assembly
85 listings referred to in these CDB files.
86 This can be used to display your program data, list
87 c or asm source code and set breakpoints.
88
89 Unfortunately, SDCDB is not quite finished and does not
90 function well enough yet to recommend for general use.
91
92
93 Usage Notes
94 ======================
95 Compile with --debug option:
96 sdcc --debug hi.c
97 This should generate .cdb symbolic debug files.
98
99 Load sdcdb, like this:
100 sdcdb hi.ihx
101
102 Then you need to do an initial "run" command.  It should hopefully
103 stop somewhere at the main() entrypoint.
104
105 Now you should be able to list code, and set breakpoints.  Type
106 "c" to continue running to a breakpoint, or type "s" to single
107 step or "n" to skip function calls.  Tpye "help" for a summary
108 of commands.
109
110 Use a preceeding bang("!") to do s51 simulator commands.  So for
111 example:
112 !pc
113 will send the "pc" command to ucSim and
114 give you the program counter and list the current line of assembly.
115 !help
116 will give you the brief command line help listing of ucSim.  But
117 this help will scroll of the screen.  So to get a list, I redirect
118 stdout to a text file to examine like this:
119 sdcdb hi.ihx 2>&1 | tee sdcdb.log
120
121 Type '.' to toggle to a full time ucSim prompt.
122
123
124 SDCDB problem areas.
125 ======================
126
127 Ok, so what are some of its problems?  Lets try to itemize
128 them so we can fix them:
129
130 * It hangs sometimes when trying to do step or next.
131
132    This probably has something to do with the context
133    sdcdb tries to build dynamically.  Sdcdb tries to
134    trace program operation by placing hidden breakpoints
135    and stepping threw the simulation between these.
136
137 * Does not print variables properly.  Seems to use the
138   wrong address for the variable. (fixed)
139
140 * ASM listing not implemented.
141   This should be easy enough to add.  This feature
142   really needs to be implemented before this is a useful
143   tool.  That or addresses of code functions need to be
144   readily available for raw ucSim commands.
145
146 * No way to browse symbols, files names.
147   Preferably, it is easy to learn the addresses of variables
148   and functions too.
149   (working on this... see new ls,lm,lf commands)
150
151 * Does not allow listing, setting breakpoints or viewing variables
152   before starting the simulation.
153   (I am fixing now, partly fixed)
154
155 * p codestr - print on code char * broken, could be CDB info invalid.
156
157
158 Changes Made
159 ======================
160
161 Added a -z option.  Any options after -z on sdcdb invocation line
162  are passed directly to ucSim.
163
164 Fixed print basic variable command(was not parsing or expecting
165   "0x" in data coming from ucSim).  Dump bit command changed from
166   "db" to "dump".
167
168 Add support for the following alternative ucSim binaries:
169  -mz80 - use "uz80" simulator.
170  -mavr - use "uavr" simulator.
171  -mxa - use "uxa" simulator.
172
173   Note that Z80(and probably avr/xa) does not produce enough
174   CDB debugging information to
175   make SDCDB useful.  Hopefully CDB support will be
176   added to these other linkers and code generators.
177
178 Added lf,lm,ls commands(list functions, list modules, list symbols).
179  This allows browsing some the CDB information SDCDB pulls in
180  to do the wonderful things it does.
181
182 Added '.' prefix/command, used alone switches back and forth
183  from ucSim/SDCDB command mode).  Also when at the (ucsim) prompt,
184  if a command is prefixed with '.' it will route the command to
185  the SDCDB command processor.  (This could obsolete the '!' prefix).
186
187
188 ======================
189
190 Fix any remaining shortcomings above and make sdcdb integrate better with
191 ucSim.
192
193 Concerning the hanging on next/step instructions:  This is critical
194 to fix.  I beleive the problem is related to SDCDB's attempt to
195 dynamically track context.  To do this, it sets many temporary break
196 points and uses these to progress step by step through the source code.
197 It does not seem reliable.  It might be an idea to offer a simplified
198 mode of stepping and breakpoints.  Need to study this more.
199
200 Make SDCDB integrate better with ucSim.
201 I think if sdcdb can act more transparently in regard to ucSim
202 it would be used more.  So stress adding value and enhancing
203 ucSim operation, and not block or hide the functionality of ucSim.
204
205 * combine print "p" & "pt" together.  We have room on the screen,
206 might as well print its type, address and value in one command.
207
208 * "fr" command prints the current position in the C code.
209 Should also print the raw code address for dumping ucSim code.
210
211
212
213 Developer Notes:
214 ======================
215 To debug, it might be helpful to turn on verbose debug dumps
216 by uncommenting #define SDCDB_DEBUG in sdcdb.h.
217
218 Some basic layout:
219 sdcdb.c - main shell of the program.
220 cmd.c - process user commands typed in.
221 simi.c - handle talking to the simulator via a socket connection.
222 symtab.c - Misc. functions to translate and process linked list
223   structures(modules, functions, symbols, etc) and CDB file
224   parsing.
225 break.c - track and implement break points.
226
227 Understanding the structures and access mechanisms of SDCDB
228 is a bit of work.  The structures include generic linked list
229 and function access.  These lists are accessed in part by the
230 functions from ../../src/SDCCset.c and SDCChash.c.  See the
231 cmd.c:infoSymbols() routine to gain some insight into these
232 main program structures.  Or type "info symbols" to dump
233 out some of these.  The new ls,lm,lf commands are also based
234 on showing information about these lists of structures.
235
236 Generic functions are used to act on these linked lists of
237 structures.  For example, in cmd.c, DEFSETFUNC(funcWithName)
238 function will find a function structure with a given name.
239 So the linked list of function structures(with the head
240 "functions") is traversed and when one is found with a matching
241 name, a pointer to the function structure is returned.
242
243 The src/SDCCset.c,SDCCset.h contain much of the core helper
244 routines to allowed to implement these linked list access
245 functions.
246
247 The dynamic context tracking is difficult to understand.
248 It has some concept of stack use, as in
249 cmd.c:printSymValue(), where it can print variables relative
250 to the stack pointer.
251