debugger build okay
[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 #ifdef _NO_GC
36
37 #define GC_malloc malloc
38 #define GC_free free
39 #define GC_realloc realloc
40
41 #else
42
43 #include "gc/gc.h"
44
45 #endif
46
47 #include "src/SDCCset.h"
48 #include "src/SDCChasht.h"
49
50 #define TRUE 1
51 #define FALSE !TRUE
52
53 typedef short bool;
54
55 #ifndef max
56 #define max(a,b) (a > b ? a : b)
57 #endif
58
59 #ifndef min
60 #define min(a,b) (a < b ? a : b)
61 #endif
62
63 #ifndef ALLOC
64 #define  ALLOC(x,sz) if (!(x = GC_malloc(sz)))                          \
65          {                                                           \
66             fprintf(stderr,"sdcdb: out of memory\n"); \
67             exit (1);                                                \
68          }
69 #endif
70 #ifndef ALLOC_ATOMIC
71 #define ALLOC_ATOMIC(x,sz)   if (!(x = GC_malloc_atomic(sz)))   \
72          {                                               \
73             fprintf(stderr,"sdcdb: out of memory\n"); \
74             exit (1);                                    \
75          }
76 #endif
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)   ;
83
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;
90
91 #define  STACK_FULL(stack)    ((p_##stack) <= stack )
92 #define  STACK_EMPTY(stack)   ((p_##stack) >= (stack +      \
93                               sizeof(stack)/sizeof(*stack)) )  
94
95 #define  STACK_PUSH_(stack,x) (*--p_##stack = (x))
96 #define  STACK_POP_(stack)    (*p_##stack++)
97
98 #define  STACK_PUSH(stack,x)  (STACK_FULL(stack)                  \
99                               ?((t_##stack)(long)(STACK_ERR(1)))  \
100                               : STACK_PUSH_(stack,x)              )
101
102 #define  STACK_POP(stack)     (STACK_EMPTY(stack)                 \
103                               ?((t_##stack)(long)(STACK_ERR(0)))  \
104                               : STACK_POP_(stack)                 )
105
106 #define  STACK_PEEK(stack)    (STACK_EMPTY(stack)                 \
107                               ?((t_##stack) NULL)                 \
108                               : *p_##stack                        )
109
110 #define  STACK_PPEEK(stack)    (((p_##stack + 1) >= (stack +      \
111                               sizeof(stack)/sizeof(*stack)))      \
112                               ?((t_##stack) NULL)                 \
113                               : *(p_##stack + 1)                  )
114
115 #define  STACK_ERR(o)         ( o                                 \
116                               ? fprintf(stderr,"stack Overflow\n")\
117                               : fprintf(stderr,"stack underflow\n"))
118
119 #define  STACK_STARTWALK(stack)   (w_##stack = p_##stack)
120
121 #define  STACK_WALK(stack)    (w_##stack >= (stack + sizeof(stack)/sizeof(*stack)) \
122                                ? NULL : *w_##stack++ )
123
124 #include "src/SDCCbitv.h"
125
126 enum {
127     SYM_REC = 1,
128     LNK_REC ,
129     FUNC_REC ,
130     STRUCT_REC,
131     MOD_REC
132 };
133
134 enum { SRC_CMODE = 1, SRC_AMODE };
135
136 /*-----------------------------------------------------------------*/
137 /*                         source line structure                   */
138 /*-----------------------------------------------------------------*/
139 typedef struct srcLine
140 {
141     unsigned addr     ;
142     short block, level; /* scope information */
143     char     *src ;
144
145 } srcLine ;
146     
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 */    
154 } cdbrecs ;
155
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*/
169 } module;
170
171 /*-----------------------------------------------------------------*/
172 /*            execution point definition                           */
173 /*-----------------------------------------------------------------*/
174 typedef struct exePoint
175 {
176     unsigned addr  ;
177     int      line  ;
178     short    block , level ;
179 } exePoint ;
180  
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 */
189     int        aentryline   ;
190     int        exitline     ;/* last line in the function  */
191     int        aexitline    ;
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                */
196 } function ;
197
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 */
205 } linkrec;
206
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       */
218 } context ;
219
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 */
225
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;
233 extern int srcMode;
234 char *searchDirsFname (char *);
235
236 #endif