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