Get debugger working with --disable-boehm-gc flag
[fw/sdcc] / debugger / mcs51 / sdcdb.h
1 /*-------------------------------------------------------------------------
2   sdcdb.h - Header file used by ALL source files for the debugger
3               Written By -  Sandeep Dutta . sandeep.dutta@usa.net (1999)
4
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
8    later version.
9    
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.
14    
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.
18    
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 -------------------------------------------------------------------------*/
23
24 #ifndef  SDCDB_H
25 #define  SDCDB_H
26
27 /* #define SDCDB_DEBUG */
28
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include <ctype.h>
33 #include <limits.h>
34 #include "sdccconf.h"
35 #include "src/SDCCalloc.h"
36 #include "src/SDCCset.h"
37 #include "src/SDCChasht.h"
38
39 #define TRUE 1
40 #define FALSE !TRUE
41
42 typedef short bool;
43
44 #ifndef max
45 #define max(a,b) (a > b ? a : b)
46 #endif
47
48 #ifndef min
49 #define min(a,b) (a < b ? a : b)
50 #endif
51
52 #ifndef ALLOC
53 #define  ALLOC(x,sz) if (!(x = GC_malloc(sz)))                          \
54          {                                                           \
55             fprintf(stderr,"sdcdb: out of memory\n"); \
56             exit (1);                                                \
57          }
58 #endif
59 #ifndef ALLOC_ATOMIC
60 #define ALLOC_ATOMIC(x,sz)   if (!(x = GC_malloc_atomic(sz)))   \
61          {                                               \
62             fprintf(stderr,"sdcdb: out of memory\n"); \
63             exit (1);                                    \
64          }
65 #endif
66 /* generalpurpose stack related macros */
67 #define  STACK_DCL(stack,type,size)                   \
68          typedef  type  t_##stack   ;                 \
69          t_##stack   stack[size]    ;                 \
70          t_##stack   (*p_##stack) = stack + (size);   \
71          t_##stack   (*w_##stack)   ;
72
73 /* define extern stack */
74 #define EXTERN_STACK_DCL(stack,type,size)             \
75         typedef type t_##stack     ;                  \
76         extern t_##stack stack[size] ;                \
77         extern t_##stack *p_##stack;                  \
78         extern t_##stack *w_##stack;
79
80 #define  STACK_FULL(stack)    ((p_##stack) <= stack )
81 #define  STACK_EMPTY(stack)   ((p_##stack) >= (stack +      \
82                               sizeof(stack)/sizeof(*stack)) )  
83
84 #define  STACK_PUSH_(stack,x) (*--p_##stack = (x))
85 #define  STACK_POP_(stack)    (*p_##stack++)
86
87 #define  STACK_PUSH(stack,x)  (STACK_FULL(stack)                  \
88                               ?((t_##stack)(long)(STACK_ERR(1)))  \
89                               : STACK_PUSH_(stack,x)              )
90
91 #define  STACK_POP(stack)     (STACK_EMPTY(stack)                 \
92                               ?((t_##stack)(long)(STACK_ERR(0)))  \
93                               : STACK_POP_(stack)                 )
94
95 #define  STACK_PEEK(stack)    (STACK_EMPTY(stack)                 \
96                               ?((t_##stack) NULL)                 \
97                               : *p_##stack                        )
98
99 #define  STACK_PPEEK(stack)    (((p_##stack + 1) >= (stack +      \
100                               sizeof(stack)/sizeof(*stack)))      \
101                               ?((t_##stack) NULL)                 \
102                               : *(p_##stack + 1)                  )
103
104 #define  STACK_ERR(o)         ( o                                 \
105                               ? fprintf(stderr,"stack Overflow\n")\
106                               : fprintf(stderr,"stack underflow\n"))
107
108 #define  STACK_STARTWALK(stack)   (w_##stack = p_##stack)
109
110 #define  STACK_WALK(stack)    (w_##stack >= (stack + sizeof(stack)/sizeof(*stack)) \
111                                ? NULL : *w_##stack++ )
112
113 #include "src/SDCCbitv.h"
114
115 enum {
116     SYM_REC = 1,
117     LNK_REC ,
118     FUNC_REC ,
119     STRUCT_REC,
120     MOD_REC
121 };
122
123 enum { SRC_CMODE = 1, SRC_AMODE };
124
125 /*-----------------------------------------------------------------*/
126 /*                         source line structure                   */
127 /*-----------------------------------------------------------------*/
128 typedef struct srcLine
129 {
130     unsigned addr     ;
131     short block, level; /* scope information */
132     char     *src ;
133
134 } srcLine ;
135     
136 /*-----------------------------------------------------------------*/
137 /*                     structure for cdb record                    */
138 /*-----------------------------------------------------------------*/
139 typedef struct  cdbrecs {
140     char type ;               /* type of line */
141     char *line;               /* contents of line */
142     struct cdbrecs *next;     /* next in chain */    
143 } cdbrecs ;
144
145 /*-----------------------------------------------------------------*/
146 /*                     module definition                           */
147 /*-----------------------------------------------------------------*/
148 typedef struct module {
149     char *cfullname ;        /* full name Includeing path for the module */
150     char *afullname;         /* fullname of assembly file */
151     char *name ;             /* name of module */
152     char *c_name;            /* c filename     */
153     char *asm_name;          /* asm file name  */
154     int   ncLines;           /* number of lines in this module */
155     int   nasmLines;         /* # of lines in the assembler file */
156     srcLine  **cLines;       /* actual source lines */    
157     srcLine  **asmLines;     /* actual assembler source lines*/
158 } module;
159
160 /*-----------------------------------------------------------------*/
161 /*            execution point definition                           */
162 /*-----------------------------------------------------------------*/
163 typedef struct exePoint
164 {
165     unsigned addr  ;
166     int      line  ;
167     short    block , level ;
168 } exePoint ;
169  
170 /*-----------------------------------------------------------------*/
171 /*                   definition for a function                     */
172 /*-----------------------------------------------------------------*/
173 typedef struct function {
174     struct symbol  *sym     ;/* pointer to symbol for function */ 
175     char           *modName ;/* module name */            
176     module         *mod     ;/* module for this function */     
177     int        entryline    ;/* first line in the function */
178     int        aentryline   ;
179     int        exitline     ;/* last line in the function  */
180     int        aexitline    ;
181     set       *cfpoints     ;/* set of all C execution points in func */   
182     set       *afpoints     ;/* set of all ASM execution points in func */
183     unsigned   int laddr    ;/* last executed address                   */
184     int        lline        ;/* last executed linenumber                */
185 } function ;
186
187 /*-----------------------------------------------------------------*/
188 /*                  link record defintion                          */
189 /*-----------------------------------------------------------------*/
190 typedef struct linkrec {
191     char type;        /* type of linker rec */
192     unsigned addr ;   /* address specified by the linker rec */
193     char *name    ;   /* name specified by linker rec */
194 } linkrec;
195
196 /*-----------------------------------------------------------------*/
197 /*                       program context                           */
198 /*-----------------------------------------------------------------*/
199 typedef struct context {    
200     function *func;           /* current function we are in */
201     char     *modName;        /* name of the module         */
202     unsigned int addr ;       /* current pc                 */
203     int      cline ;          /* current c line number      */
204     int      asmline;         /* current asm line number    */
205     int      block ;          /* current block number       */
206     int      level ;          /* current level number       */
207 } context ;
208
209 extern cdbrecs *recsRoot ;
210 extern context *currCtxt ;
211 extern set *modules  ; /* set of modules   */
212 extern set *functions; /* set of functions */
213 extern set *symbols  ; /* set of symbols */
214
215 extern int nStructs ;
216 extern struct structdef **structs ; /* all structures */
217 extern char *ssdirl; /* source directory search path */
218 void **resize (void **, int );
219 char  *alloccpy(char *,int );
220 srcLine **loadFile (char *name, int *nlines);
221 extern short fullname;
222 extern int srcMode;
223 char *searchDirsFname (char *);
224
225 #endif