1 /*-------------------------------------------------------------------------
2 sdcdb.h - Header file used by ALL source files for the debugger
3 Written By - Sandeep Dutta . sandeep.dutta@usa.net (1999)
5 This program is free software; you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published by the
7 Free Software Foundation; either version 2, or (at your option) any
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 In other words, you are welcome to use, share and improve this program.
20 You are forbidden to forbid anyone else to use, share and improve
21 what you give them. Help stamp out software-hoarding!
22 -------------------------------------------------------------------------*/
30 // set D_x to 0 to turn off, 1 to turn on.
36 extern int sdcdbDebug;
38 #define Dprintf(f, fs) {if (f & sdcdbDebug) printf fs ; }
40 #define Dprintf(f, fs) { }
49 #include "src/SDCCset.h"
50 #include "src/SDCChasht.h"
58 #define max(a,b) (a > b ? a : b)
62 #define min(a,b) (a < b ? a : b)
67 * #define ALLOC(x,sz) if (!(x = calloc(1, sz))) \
69 * fprintf(stderr,"sdcdb: out of memory\n"); \
73 * #ifndef ALLOC_ATOMIC
74 * #define ALLOC_ATOMIC(x,sz) if (!(x = calloc(1, sz))) \
76 * fprintf(stderr,"sdcdb: out of memory\n"); \
82 /* generalpurpose stack related macros */
83 #define STACK_DCL(stack,type,size) \
84 typedef type t_##stack ; \
85 t_##stack stack[size] ; \
86 t_##stack (*p_##stack) = stack + (size); \
87 t_##stack (*w_##stack) ;
89 /* define extern stack */
90 #define EXTERN_STACK_DCL(stack,type,size) \
91 typedef type t_##stack ; \
92 extern t_##stack stack[size] ; \
93 extern t_##stack *p_##stack; \
94 extern t_##stack *w_##stack;
96 #define STACK_FULL(stack) ((p_##stack) <= stack )
97 #define STACK_EMPTY(stack) ((p_##stack) >= (stack + \
98 sizeof(stack)/sizeof(*stack)) )
100 #define STACK_PUSH_(stack,x) (*--p_##stack = (x))
101 #define STACK_POP_(stack) (*p_##stack++)
103 #define STACK_PUSH(stack,x) (STACK_FULL(stack) \
104 ?((t_##stack)(long)(STACK_ERR(1))) \
105 : STACK_PUSH_(stack,x) )
107 #define STACK_POP(stack) (STACK_EMPTY(stack) \
108 ?((t_##stack) NULL) \
109 : STACK_POP_(stack) )
111 #define STACK_PEEK(stack) (STACK_EMPTY(stack) \
112 ?((t_##stack) NULL) \
115 #define STACK_PPEEK(stack) (((p_##stack + 1) >= (stack + \
116 sizeof(stack)/sizeof(*stack))) \
117 ?((t_##stack) NULL) \
120 #define STACK_ERR(o) ( o \
121 ? fprintf(stderr,"stack Overflow\n")\
122 : fprintf(stderr,"stack underflow\n"))
124 #define STACK_STARTWALK(stack) (w_##stack = p_##stack)
126 #define STACK_WALK(stack) (w_##stack >= (stack + sizeof(stack)/sizeof(*stack)) \
127 ? NULL : *w_##stack++ )
129 #include "src/SDCCbitv.h"
147 enum { SRC_CMODE = 1, SRC_AMODE };
149 /*-----------------------------------------------------------------*/
150 /* source line structure */
151 /*-----------------------------------------------------------------*/
152 typedef struct srcLine
155 short block, level; /* scope information */
160 /*-----------------------------------------------------------------*/
161 /* structure for cdb record */
162 /*-----------------------------------------------------------------*/
163 typedef struct cdbrecs {
164 char type ; /* type of line */
165 char *line; /* contents of line */
166 struct cdbrecs *next; /* next in chain */
169 /*-----------------------------------------------------------------*/
170 /* module definition */
171 /*-----------------------------------------------------------------*/
172 typedef struct module {
173 char *cfullname ; /* full name Includeing path for the module */
174 char *afullname; /* fullname of assembly file */
175 char *name ; /* name of module */
176 char *c_name; /* c filename */
177 char *asm_name; /* asm file name */
178 int ncLines; /* number of lines in this module */
179 int nasmLines; /* # of lines in the assembler file */
180 srcLine **cLines; /* actual source lines */
181 srcLine **asmLines; /* actual assembler source lines*/
182 set *cfpoints; /* set of double line execution points */
185 /*-----------------------------------------------------------------*/
186 /* execution point definition */
187 /*-----------------------------------------------------------------*/
188 typedef struct exePoint
192 short block , level ;
195 /*-----------------------------------------------------------------*/
196 /* definition for a function */
197 /*-----------------------------------------------------------------*/
198 typedef struct function {
199 struct symbol *sym ;/* pointer to symbol for function */
200 char *modName ;/* module name */
201 module *mod ;/* module for this function */
202 int entryline ;/* first line in the function */
204 int exitline ;/* last line in the function */
206 set *cfpoints ;/* set of all C execution points in func */
207 set *afpoints ;/* set of all ASM execution points in func */
208 unsigned int laddr ;/* last executed address */
209 int lline ;/* last executed linenumber */
210 unsigned int stkaddr ;/* stackpointer at beginning of function
211 * (not reentrant ! ) only actual */
214 /*-----------------------------------------------------------------*/
215 /* link record defintion */
216 /*-----------------------------------------------------------------*/
217 typedef struct linkrec {
218 char type; /* type of linker rec */
219 unsigned addr ; /* address specified by the linker rec */
220 char *name ; /* name specified by linker rec */
223 /*-----------------------------------------------------------------*/
224 /* program context */
225 /*-----------------------------------------------------------------*/
226 typedef struct context {
227 function *func; /* current function we are in */
228 char *modName; /* name of the module */
229 unsigned int addr ; /* current pc */
230 int cline ; /* current c line number */
231 int asmline; /* current asm line number */
232 int block ; /* current block number */
233 int level ; /* current level number */
236 /*-----------------------------------------------------------------*/
237 /* symbol display information */
238 /*-----------------------------------------------------------------*/
239 typedef struct _dsymbol
248 extern cdbrecs *recsRoot ;
249 extern context *currCtxt ;
250 extern set *modules ; /* set of modules */
251 extern set *functions; /* set of functions */
252 extern set *symbols ; /* set of symbols */
253 extern set *sfrsymbols;/* set of symbols of sfr or sbit */
254 extern set *dispsymbols; /* set of displayable symbols */
257 extern char *currModName ;
258 extern char userinterrupt ;
259 extern char nointerrupt ;
260 extern short showfull ;
261 extern int nStructs ;
262 extern struct structdef **structs ; /* all structures */
263 extern char *ssdirl; /* source directory search path */
264 void **resize (void **, int );
265 char *alloccpy(char *,int );
266 char *gc_strdup(const char *s);
267 srcLine **loadFile (char *name, int *nlines);
269 extern short fullname;
272 char *searchDirsFname (char *);
273 char *getNextCmdLine(void );
274 void setCmdLine( char * );
275 void stopCommandList( void );
277 /* trimming functions */
278 extern char *trim_left(char *s);
279 extern char *trim_right(char *s);
280 extern char *trim(char *s);