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_VERSION "0.9"
32 // set D_x to 0 to turn off, 1 to turn on.
38 extern int sdcdbDebug
;
40 #define Dprintf(f, fs) {if (f & sdcdbDebug) printf fs ; }
42 #define Dprintf(f, fs) { }
52 #elif defined(_WIN32) && !defined(__MINGW32__)
55 # include "sdccconf.h"
57 #include "src/SDCCset.h"
58 #include "src/SDCChasht.h"
66 #define max(a,b) (a > b ? a : b)
70 #define min(a,b) (a < b ? a : b)
75 * #define ALLOC(x,sz) if (!(x = calloc(1, sz))) \
77 * fprintf(stderr,"sdcdb: out of memory\n"); \
81 * #ifndef ALLOC_ATOMIC
82 * #define ALLOC_ATOMIC(x,sz) if (!(x = calloc(1, sz))) \
84 * fprintf(stderr,"sdcdb: out of memory\n"); \
90 /* generalpurpose stack related macros */
91 #define STACK_DCL(stack, type, size) \
92 typedef type t_##stack; \
93 t_##stack stack[size]; \
94 t_##stack *p_##stack = stack - 1; \
97 /* define extern stack */
98 #define EXTERN_STACK_DCL(stack, type, size) \
99 typedef type t_##stack; \
100 extern t_##stack stack[size]; \
101 extern t_##stack *p_##stack; \
102 extern t_##stack *w_##stack;
104 #define STACK_EMPTY(stack) ((p_##stack) < stack)
105 #define STACK_FULL(stack) ((p_##stack) >= (stack + \
106 sizeof(stack) / sizeof(*stack) - 1) )
108 #define STACK_PUSH_(stack, x) (*++p_##stack = (x))
109 #define STACK_POP_(stack) (*p_##stack--)
111 #define STACK_PUSH(stack, x) (STACK_FULL(stack) \
112 ? (STACK_ERR(1, stack), *p_##stack) \
113 : STACK_PUSH_(stack, x) )
115 #define STACK_POP(stack) (STACK_EMPTY(stack) \
116 ? (STACK_ERR(-1, stack), *stack) \
117 : STACK_POP_(stack) )
119 #define STACK_PEEK(stack) (STACK_EMPTY(stack) \
120 ? (STACK_ERR(0, stack), *stack) \
123 #define STACK_PPEEK(stack) (((p_##stack - 1) < stack) \
124 ? (STACK_ERR(0, stack), *stack) \
127 #define STACK_ERR(o, stack) (fprintf(stderr, "stack '%s' %s\n", \
135 #define STACK_STARTWALK(stack) (w_##stack = p_##stack)
137 #define STACK_WALK(stack) (w_##stack >= stack \
138 ? NULL : STACK_POP_(stack) )
140 #include "src/SDCCbitv.h"
158 enum { SRC_CMODE
= 1, SRC_AMODE
};
160 /*-----------------------------------------------------------------*/
161 /* source line structure */
162 /*-----------------------------------------------------------------*/
163 typedef struct srcLine
167 int level
; /* scope information */
172 /*-----------------------------------------------------------------*/
173 /* structure for cdb record */
174 /*-----------------------------------------------------------------*/
175 typedef struct cdbrecs
{
176 char type
; /* type of line */
177 char *line
; /* contents of line */
178 struct cdbrecs
*next
; /* next in chain */
181 /*-----------------------------------------------------------------*/
182 /* module definition */
183 /*-----------------------------------------------------------------*/
184 typedef struct module
{
185 char *cfullname
; /* full name Includeing path for the module */
186 char *afullname
; /* fullname of assembly file */
187 char *name
; /* name of module */
188 char *c_name
; /* c filename */
189 char *asm_name
; /* asm file name */
190 int ncLines
; /* number of lines in this module */
191 int nasmLines
; /* # of lines in the assembler file */
192 srcLine
**cLines
; /* actual source lines */
193 srcLine
**asmLines
; /* actual assembler source lines*/
194 set
*cfpoints
; /* set of double line execution points */
197 /*-----------------------------------------------------------------*/
198 /* execution point definition */
199 /*-----------------------------------------------------------------*/
200 typedef struct exePoint
208 /*-----------------------------------------------------------------*/
209 /* definition for a function */
210 /*-----------------------------------------------------------------*/
211 typedef struct function
{
212 struct symbol
*sym
;/* pointer to symbol for function */
213 char *modName
;/* module name */
214 module
*mod
;/* module for this function */
215 int entryline
;/* first line in the function */
217 int exitline
;/* last line in the function */
219 set
*cfpoints
;/* set of all C execution points in func */
220 set
*afpoints
;/* set of all ASM execution points in func */
221 unsigned int laddr
;/* last executed address */
222 int lline
;/* last executed linenumber */
223 unsigned int stkaddr
;/* stackpointer at beginning of function
224 * (not reentrant ! ) only actual */
227 /*-----------------------------------------------------------------*/
228 /* link record defintion */
229 /*-----------------------------------------------------------------*/
230 typedef struct linkrec
{
231 char type
; /* type of linker rec */
232 unsigned addr
; /* address specified by the linker rec */
233 char *name
; /* name specified by linker rec */
236 /*-----------------------------------------------------------------*/
237 /* program context */
238 /*-----------------------------------------------------------------*/
239 typedef struct context
{
240 function
*func
; /* current function we are in */
241 char *modName
; /* name of the module */
242 unsigned int addr
; /* current pc */
243 int cline
; /* current c line number */
244 int asmline
; /* current asm line number */
245 int block
; /* current block number */
246 int level
; /* current level number */
249 /*-----------------------------------------------------------------*/
250 /* symbol display information */
251 /*-----------------------------------------------------------------*/
252 typedef struct _dsymbol
261 extern cdbrecs
*recsRoot
;
262 extern context
*currCtxt
;
263 extern set
*modules
; /* set of modules */
264 extern set
*functions
; /* set of functions */
265 extern set
*symbols
; /* set of symbols */
266 extern set
*sfrsymbols
;/* set of symbols of sfr or sbit */
267 extern set
*dispsymbols
; /* set of displayable symbols */
270 extern char *currModName
;
271 extern char userinterrupt
;
272 extern char nointerrupt
;
273 extern short showfull
;
274 extern int nStructs
;
275 extern struct structdef
**structs
; /* all structures */
276 extern char *ssdirl
; /* source directory search path */
277 void **resize (void **, int );
278 char *alloccpy(char *,int );
279 char *gc_strdup(const char *s
);
280 srcLine
**loadFile (char *name
, int *nlines
);
282 extern short fullname
;
285 char *searchDirsFname (char *);
286 char *getNextCmdLine(void);
287 void setCmdLine(char *);
288 void stopCommandList(void);
290 char *argsToCmdLine(char **args
, int nargs
);
292 /* trimming functions */
293 extern char *trim_left(char *s
);
294 extern char *trim_right(char *s
);
295 extern char *trim(char *s
);