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