Initial revision
[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
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)   ;
77
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;
84
85 #define  STACK_FULL(stack)    ((p_##stack) <= stack )
86 #define  STACK_EMPTY(stack)   ((p_##stack) >= (stack +      \
87                               sizeof(stack)/sizeof(*stack)) )  
88
89 #define  STACK_PUSH_(stack,x) (*--p_##stack = (x))
90 #define  STACK_POP_(stack)    (*p_##stack++)
91
92 #define  STACK_PUSH(stack,x)  (STACK_FULL(stack)                  \
93                               ?((t_##stack)(long)(STACK_ERR(1)))  \
94                               : STACK_PUSH_(stack,x)              )
95
96 #define  STACK_POP(stack)     (STACK_EMPTY(stack)                 \
97                               ?((t_##stack)(long)(STACK_ERR(0)))  \
98                               : STACK_POP_(stack)                 )
99
100 #define  STACK_PEEK(stack)    (STACK_EMPTY(stack)                 \
101                               ?((t_##stack) NULL)                 \
102                               : *p_##stack                        )
103
104 #define  STACK_PPEEK(stack)    (((p_##stack + 1) >= (stack +      \
105                               sizeof(stack)/sizeof(*stack)))      \
106                               ?((t_##stack) NULL)                 \
107                               : *(p_##stack + 1)                  )
108
109 #define  STACK_ERR(o)         ( o                                 \
110                               ? fprintf(stderr,"stack Overflow\n")\
111                               : fprintf(stderr,"stack underflow\n"))
112
113 #define  STACK_STARTWALK(stack)   (w_##stack = p_##stack)
114
115 #define  STACK_WALK(stack)    (w_##stack >= (stack + sizeof(stack)/sizeof(*stack)) \
116                                ? NULL : *w_##stack++ )
117
118 #include "../sdcc.src/SDCCbitv.h"
119
120 enum {
121     SYM_REC = 1,
122     LNK_REC ,
123     FUNC_REC ,
124     STRUCT_REC,
125     MOD_REC
126 };
127
128 enum { SRC_CMODE = 1, SRC_AMODE };
129
130 /*-----------------------------------------------------------------*/
131 /*                         source line structure                   */
132 /*-----------------------------------------------------------------*/
133 typedef struct srcLine
134 {
135     unsigned addr     ;
136     short block, level; /* scope information */
137     char     *src ;
138
139 } srcLine ;
140     
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 */    
148 } cdbrecs ;
149
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*/
163 } module;
164
165 /*-----------------------------------------------------------------*/
166 /*            execution point definition                           */
167 /*-----------------------------------------------------------------*/
168 typedef struct exePoint
169 {
170     unsigned addr  ;
171     int      line  ;
172     short    block , level ;
173 } exePoint ;
174  
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 */
183     int        aentryline   ;
184     int        exitline     ;/* last line in the function  */
185     int        aexitline    ;
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                */
190 } function ;
191
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 */
199 } linkrec;
200
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       */
212 } context ;
213
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 */
219
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;
227 extern int srcMode;
228 char *searchDirsFname (char *);
229
230 #endif