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 */
30 // set D_x to 0 to turn off, 1 to turn on.
36 #define Dprintf(f, fs) {if (f) printf fs ; }
38 #define Dprintf(f, fs) { }
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)
65 * #define ALLOC(x,sz) if (!(x = calloc(1, sz))) \
67 * fprintf(stderr,"sdcdb: out of memory\n"); \
71 * #ifndef ALLOC_ATOMIC
72 * #define ALLOC_ATOMIC(x,sz) if (!(x = calloc(1, sz))) \
74 * fprintf(stderr,"sdcdb: out of memory\n"); \
80 /* generalpurpose stack related macros */
81 #define STACK_DCL(stack,type,size) \
82 typedef type t_##stack ; \
83 t_##stack stack[size] ; \
84 t_##stack (*p_##stack) = stack + (size); \
85 t_##stack (*w_##stack) ;
87 /* define extern stack */
88 #define EXTERN_STACK_DCL(stack,type,size) \
89 typedef type t_##stack ; \
90 extern t_##stack stack[size] ; \
91 extern t_##stack *p_##stack; \
92 extern t_##stack *w_##stack;
94 #define STACK_FULL(stack) ((p_##stack) <= stack )
95 #define STACK_EMPTY(stack) ((p_##stack) >= (stack + \
96 sizeof(stack)/sizeof(*stack)) )
98 #define STACK_PUSH_(stack,x) (*--p_##stack = (x))
99 #define STACK_POP_(stack) (*p_##stack++)
101 #define STACK_PUSH(stack,x) (STACK_FULL(stack) \
102 ?((t_##stack)(long)(STACK_ERR(1))) \
103 : STACK_PUSH_(stack,x) )
105 #define STACK_POP(stack) (STACK_EMPTY(stack) \
106 ?((t_##stack)(long)(STACK_ERR(0))) \
107 : STACK_POP_(stack) )
109 #define STACK_PEEK(stack) (STACK_EMPTY(stack) \
110 ?((t_##stack) NULL) \
113 #define STACK_PPEEK(stack) (((p_##stack + 1) >= (stack + \
114 sizeof(stack)/sizeof(*stack))) \
115 ?((t_##stack) NULL) \
118 #define STACK_ERR(o) ( o \
119 ? fprintf(stderr,"stack Overflow\n")\
120 : fprintf(stderr,"stack underflow\n"))
122 #define STACK_STARTWALK(stack) (w_##stack = p_##stack)
124 #define STACK_WALK(stack) (w_##stack >= (stack + sizeof(stack)/sizeof(*stack)) \
125 ? NULL : *w_##stack++ )
127 #include "src/SDCCbitv.h"
137 enum { SRC_CMODE = 1, SRC_AMODE };
139 /*-----------------------------------------------------------------*/
140 /* source line structure */
141 /*-----------------------------------------------------------------*/
142 typedef struct srcLine
145 short block, level; /* scope information */
150 /*-----------------------------------------------------------------*/
151 /* structure for cdb record */
152 /*-----------------------------------------------------------------*/
153 typedef struct cdbrecs {
154 char type ; /* type of line */
155 char *line; /* contents of line */
156 struct cdbrecs *next; /* next in chain */
159 /*-----------------------------------------------------------------*/
160 /* module definition */
161 /*-----------------------------------------------------------------*/
162 typedef struct module {
163 char *cfullname ; /* full name Includeing path for the module */
164 char *afullname; /* fullname of assembly file */
165 char *name ; /* name of module */
166 char *c_name; /* c filename */
167 char *asm_name; /* asm file name */
168 int ncLines; /* number of lines in this module */
169 int nasmLines; /* # of lines in the assembler file */
170 srcLine **cLines; /* actual source lines */
171 srcLine **asmLines; /* actual assembler source lines*/
174 /*-----------------------------------------------------------------*/
175 /* execution point definition */
176 /*-----------------------------------------------------------------*/
177 typedef struct exePoint
181 short block , level ;
184 /*-----------------------------------------------------------------*/
185 /* definition for a function */
186 /*-----------------------------------------------------------------*/
187 typedef struct function {
188 struct symbol *sym ;/* pointer to symbol for function */
189 char *modName ;/* module name */
190 module *mod ;/* module for this function */
191 int entryline ;/* first line in the function */
193 int exitline ;/* last line in the function */
195 set *cfpoints ;/* set of all C execution points in func */
196 set *afpoints ;/* set of all ASM execution points in func */
197 unsigned int laddr ;/* last executed address */
198 int lline ;/* last executed linenumber */
201 /*-----------------------------------------------------------------*/
202 /* link record defintion */
203 /*-----------------------------------------------------------------*/
204 typedef struct linkrec {
205 char type; /* type of linker rec */
206 unsigned addr ; /* address specified by the linker rec */
207 char *name ; /* name specified by linker rec */
210 /*-----------------------------------------------------------------*/
211 /* program context */
212 /*-----------------------------------------------------------------*/
213 typedef struct context {
214 function *func; /* current function we are in */
215 char *modName; /* name of the module */
216 unsigned int addr ; /* current pc */
217 int cline ; /* current c line number */
218 int asmline; /* current asm line number */
219 int block ; /* current block number */
220 int level ; /* current level number */
223 extern cdbrecs *recsRoot ;
224 extern context *currCtxt ;
225 extern set *modules ; /* set of modules */
226 extern set *functions; /* set of functions */
227 extern set *symbols ; /* set of symbols */
229 extern int nStructs ;
230 extern struct structdef **structs ; /* all structures */
231 extern char *ssdirl; /* source directory search path */
232 void **resize (void **, int );
233 char *alloccpy(char *,int );
234 srcLine **loadFile (char *name, int *nlines);
235 extern short fullname;
237 char *searchDirsFname (char *);