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 -------------------------------------------------------------------------*/
27 /* #define SDCDB_DEBUG */
37 #define GC_malloc malloc
39 #define GC_realloc realloc
47 #include "src/SDCCset.h"
48 #include "src/SDCChasht.h"
56 #define max(a,b) (a > b ? a : b)
60 #define min(a,b) (a < b ? a : b)
64 #define ALLOC(x,sz) if (!(x = GC_malloc(sz))) \
66 fprintf(stderr,"sdcdb: out of memory\n"); \
71 #define ALLOC_ATOMIC(x,sz) if (!(x = GC_malloc_atomic(sz))) \
73 fprintf(stderr,"sdcdb: out of memory\n"); \
77 /* generalpurpose stack related macros */
78 #define STACK_DCL(stack,type,size) \
79 typedef type t_##stack ; \
80 t_##stack stack[size] ; \
81 t_##stack (*p_##stack) = stack + (size); \
82 t_##stack (*w_##stack) ;
84 /* define extern stack */
85 #define EXTERN_STACK_DCL(stack,type,size) \
86 typedef type t_##stack ; \
87 extern t_##stack stack[size] ; \
88 extern t_##stack *p_##stack; \
89 extern t_##stack *w_##stack;
91 #define STACK_FULL(stack) ((p_##stack) <= stack )
92 #define STACK_EMPTY(stack) ((p_##stack) >= (stack + \
93 sizeof(stack)/sizeof(*stack)) )
95 #define STACK_PUSH_(stack,x) (*--p_##stack = (x))
96 #define STACK_POP_(stack) (*p_##stack++)
98 #define STACK_PUSH(stack,x) (STACK_FULL(stack) \
99 ?((t_##stack)(long)(STACK_ERR(1))) \
100 : STACK_PUSH_(stack,x) )
102 #define STACK_POP(stack) (STACK_EMPTY(stack) \
103 ?((t_##stack)(long)(STACK_ERR(0))) \
104 : STACK_POP_(stack) )
106 #define STACK_PEEK(stack) (STACK_EMPTY(stack) \
107 ?((t_##stack) NULL) \
110 #define STACK_PPEEK(stack) (((p_##stack + 1) >= (stack + \
111 sizeof(stack)/sizeof(*stack))) \
112 ?((t_##stack) NULL) \
115 #define STACK_ERR(o) ( o \
116 ? fprintf(stderr,"stack Overflow\n")\
117 : fprintf(stderr,"stack underflow\n"))
119 #define STACK_STARTWALK(stack) (w_##stack = p_##stack)
121 #define STACK_WALK(stack) (w_##stack >= (stack + sizeof(stack)/sizeof(*stack)) \
122 ? NULL : *w_##stack++ )
124 #include "src/SDCCbitv.h"
134 enum { SRC_CMODE = 1, SRC_AMODE };
136 /*-----------------------------------------------------------------*/
137 /* source line structure */
138 /*-----------------------------------------------------------------*/
139 typedef struct srcLine
142 short block, level; /* scope information */
147 /*-----------------------------------------------------------------*/
148 /* structure for cdb record */
149 /*-----------------------------------------------------------------*/
150 typedef struct cdbrecs {
151 char type ; /* type of line */
152 char *line; /* contents of line */
153 struct cdbrecs *next; /* next in chain */
156 /*-----------------------------------------------------------------*/
157 /* module definition */
158 /*-----------------------------------------------------------------*/
159 typedef struct module {
160 char *cfullname ; /* full name Includeing path for the module */
161 char *afullname; /* fullname of assembly file */
162 char *name ; /* name of module */
163 char *c_name; /* c filename */
164 char *asm_name; /* asm file name */
165 int ncLines; /* number of lines in this module */
166 int nasmLines; /* # of lines in the assembler file */
167 srcLine **cLines; /* actual source lines */
168 srcLine **asmLines; /* actual assembler source lines*/
171 /*-----------------------------------------------------------------*/
172 /* execution point definition */
173 /*-----------------------------------------------------------------*/
174 typedef struct exePoint
178 short block , level ;
181 /*-----------------------------------------------------------------*/
182 /* definition for a function */
183 /*-----------------------------------------------------------------*/
184 typedef struct function {
185 struct symbol *sym ;/* pointer to symbol for function */
186 char *modName ;/* module name */
187 module *mod ;/* module for this function */
188 int entryline ;/* first line in the function */
190 int exitline ;/* last line in the function */
192 set *cfpoints ;/* set of all C execution points in func */
193 set *afpoints ;/* set of all ASM execution points in func */
194 unsigned int laddr ;/* last executed address */
195 int lline ;/* last executed linenumber */
198 /*-----------------------------------------------------------------*/
199 /* link record defintion */
200 /*-----------------------------------------------------------------*/
201 typedef struct linkrec {
202 char type; /* type of linker rec */
203 unsigned addr ; /* address specified by the linker rec */
204 char *name ; /* name specified by linker rec */
207 /*-----------------------------------------------------------------*/
208 /* program context */
209 /*-----------------------------------------------------------------*/
210 typedef struct context {
211 function *func; /* current function we are in */
212 char *modName; /* name of the module */
213 unsigned int addr ; /* current pc */
214 int cline ; /* current c line number */
215 int asmline; /* current asm line number */
216 int block ; /* current block number */
217 int level ; /* current level number */
220 extern cdbrecs *recsRoot ;
221 extern context *currCtxt ;
222 extern set *modules ; /* set of modules */
223 extern set *functions; /* set of functions */
224 extern set *symbols ; /* set of symbols */
226 extern int nStructs ;
227 extern struct structdef **structs ; /* all structures */
228 extern char *ssdirl; /* source directory search path */
229 void **resize (void **, int );
230 char *alloccpy(char *,int );
231 srcLine **loadFile (char *name, int *nlines);
232 extern short fullname;
234 char *searchDirsFname (char *);