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