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