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 /* generalpurpose stack related macros */
72 #define STACK_DCL(stack,type,size) \
73 typedef type t_##stack ; \
74 t_##stack stack[size] ; \
75 t_##stack (*p_##stack) = stack + (size); \
76 t_##stack (*w_##stack) ;
78 /* define extern stack */
79 #define EXTERN_STACK_DCL(stack,type,size) \
80 typedef type t_##stack ; \
81 extern t_##stack stack[size] ; \
82 extern t_##stack *p_##stack; \
83 extern t_##stack *w_##stack;
85 #define STACK_FULL(stack) ((p_##stack) <= stack )
86 #define STACK_EMPTY(stack) ((p_##stack) >= (stack + \
87 sizeof(stack)/sizeof(*stack)) )
89 #define STACK_PUSH_(stack,x) (*--p_##stack = (x))
90 #define STACK_POP_(stack) (*p_##stack++)
92 #define STACK_PUSH(stack,x) (STACK_FULL(stack) \
93 ?((t_##stack)(long)(STACK_ERR(1))) \
94 : STACK_PUSH_(stack,x) )
96 #define STACK_POP(stack) (STACK_EMPTY(stack) \
97 ?((t_##stack)(long)(STACK_ERR(0))) \
100 #define STACK_PEEK(stack) (STACK_EMPTY(stack) \
101 ?((t_##stack) NULL) \
104 #define STACK_PPEEK(stack) (((p_##stack + 1) >= (stack + \
105 sizeof(stack)/sizeof(*stack))) \
106 ?((t_##stack) NULL) \
109 #define STACK_ERR(o) ( o \
110 ? fprintf(stderr,"stack Overflow\n")\
111 : fprintf(stderr,"stack underflow\n"))
113 #define STACK_STARTWALK(stack) (w_##stack = p_##stack)
115 #define STACK_WALK(stack) (w_##stack >= (stack + sizeof(stack)/sizeof(*stack)) \
116 ? NULL : *w_##stack++ )
118 #include "../sdcc.src/SDCCbitv.h"
128 enum { SRC_CMODE = 1, SRC_AMODE };
130 /*-----------------------------------------------------------------*/
131 /* source line structure */
132 /*-----------------------------------------------------------------*/
133 typedef struct srcLine
136 short block, level; /* scope information */
141 /*-----------------------------------------------------------------*/
142 /* structure for cdb record */
143 /*-----------------------------------------------------------------*/
144 typedef struct cdbrecs {
145 char type ; /* type of line */
146 char *line; /* contents of line */
147 struct cdbrecs *next; /* next in chain */
150 /*-----------------------------------------------------------------*/
151 /* module definition */
152 /*-----------------------------------------------------------------*/
153 typedef struct module {
154 char *cfullname ; /* full name Includeing path for the module */
155 char *afullname; /* fullname of assembly file */
156 char *name ; /* name of module */
157 char *c_name; /* c filename */
158 char *asm_name; /* asm file name */
159 int ncLines; /* number of lines in this module */
160 int nasmLines; /* # of lines in the assembler file */
161 srcLine **cLines; /* actual source lines */
162 srcLine **asmLines; /* actual assembler source lines*/
165 /*-----------------------------------------------------------------*/
166 /* execution point definition */
167 /*-----------------------------------------------------------------*/
168 typedef struct exePoint
172 short block , level ;
175 /*-----------------------------------------------------------------*/
176 /* definition for a function */
177 /*-----------------------------------------------------------------*/
178 typedef struct function {
179 struct symbol *sym ;/* pointer to symbol for function */
180 char *modName ;/* module name */
181 module *mod ;/* module for this function */
182 int entryline ;/* first line in the function */
184 int exitline ;/* last line in the function */
186 set *cfpoints ;/* set of all C execution points in func */
187 set *afpoints ;/* set of all ASM execution points in func */
188 unsigned int laddr ;/* last executed address */
189 int lline ;/* last executed linenumber */
192 /*-----------------------------------------------------------------*/
193 /* link record defintion */
194 /*-----------------------------------------------------------------*/
195 typedef struct linkrec {
196 char type; /* type of linker rec */
197 unsigned addr ; /* address specified by the linker rec */
198 char *name ; /* name specified by linker rec */
201 /*-----------------------------------------------------------------*/
202 /* program context */
203 /*-----------------------------------------------------------------*/
204 typedef struct context {
205 function *func; /* current function we are in */
206 char *modName; /* name of the module */
207 unsigned int addr ; /* current pc */
208 int cline ; /* current c line number */
209 int asmline; /* current asm line number */
210 int block ; /* current block number */
211 int level ; /* current level number */
214 extern cdbrecs *recsRoot ;
215 extern context *currCtxt ;
216 extern set *modules ; /* set of modules */
217 extern set *functions; /* set of functions */
218 extern set *symbols ; /* set of symbols */
220 extern int nStructs ;
221 extern struct structdef **structs ; /* all structures */
222 extern char *ssdirl; /* source directory search path */
223 void **resize (void **, int );
224 char *alloccpy(char *,int );
225 srcLine **loadFile (char *name, int *nlines);
226 extern short fullname;
228 char *searchDirsFname (char *);