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