Extract call stack from running machine.
[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 "config.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 #include "src/SDCCbitv.h"
83
84 enum {
85     SYM_REC = 1,
86     LNK_REC ,
87     FUNC_REC ,
88     STRUCT_REC,
89     MOD_REC
90 };
91
92 enum {
93     FMT_NON =  0,
94     FMT_BIN =  1,
95     FMT_OCT =  2,
96     FMT_DEZ =  3,
97     FMT_HEX =  4
98 };
99
100 enum { SRC_CMODE = 1, SRC_AMODE };
101
102 /*-----------------------------------------------------------------*/
103 /*                         source line structure                   */
104 /*-----------------------------------------------------------------*/
105 typedef struct srcLine
106 {
107     unsigned addr     ;
108     short block, level; /* scope information */
109     char     *src ;
110
111 } srcLine ;
112
113 /*-----------------------------------------------------------------*/
114 /*                     structure for cdb record                    */
115 /*-----------------------------------------------------------------*/
116 typedef struct  cdbrecs {
117     char type ;               /* type of line */
118     char *line;               /* contents of line */
119     struct cdbrecs *next;     /* next in chain */
120 } cdbrecs ;
121
122 /*-----------------------------------------------------------------*/
123 /*                     module definition                           */
124 /*-----------------------------------------------------------------*/
125 typedef struct module {
126     char *cfullname ;        /* full name Includeing path for the module */
127     char *afullname;         /* fullname of assembly file */
128     char *name ;             /* name of module */
129     char *c_name;            /* c filename     */
130     char *asm_name;          /* asm file name  */
131     int   ncLines;           /* number of lines in this module */
132     int   nasmLines;         /* # of lines in the assembler file */
133     srcLine  **cLines;       /* actual source lines */
134     srcLine  **asmLines;     /* actual assembler source lines*/
135     set       *cfpoints;     /* set of double line execution points */
136 } module;
137
138 /*-----------------------------------------------------------------*/
139 /*            execution point definition                           */
140 /*-----------------------------------------------------------------*/
141 typedef struct exePoint
142 {
143     unsigned addr  ;
144     int      line  ;
145     short    block , level ;
146 } exePoint ;
147
148 /*-----------------------------------------------------------------*/
149 /*                   definition for a function                     */
150 /*-----------------------------------------------------------------*/
151 typedef struct function {
152     struct symbol  *sym     ;/* pointer to symbol for function */
153     char           *modName ;/* module name */
154     module         *mod     ;/* module for this function */
155     int        entryline    ;/* first line in the function */
156     int        aentryline   ;
157     int        exitline     ;/* last line in the function  */
158     int        aexitline    ;
159     set       *cfpoints     ;/* set of all C execution points in func   */
160     set       *afpoints     ;/* set of all ASM execution points in func */
161     unsigned   int laddr    ;/* last executed address                   */
162     int        lline        ;/* last executed linenumber                */
163     unsigned   int stkaddr  ;/* stackpointer at beginning of function
164                               * (not reentrant ! ) only actual */
165 } function ;
166
167 /*-----------------------------------------------------------------*/
168 /*                  link record defintion                          */
169 /*-----------------------------------------------------------------*/
170 typedef struct linkrec {
171     char type;        /* type of linker rec */
172     unsigned addr ;   /* address specified by the linker rec */
173     char *name    ;   /* name specified by linker rec */
174 } linkrec;
175
176 /*-----------------------------------------------------------------*/
177 /*                       program context                           */
178 /*-----------------------------------------------------------------*/
179 typedef struct context {
180     function *func;           /* current function we are in */
181     char     *modName;        /* name of the module         */
182     unsigned int addr ;       /* current pc                 */
183     int      cline ;          /* current c line number      */
184     int      asmline;         /* current asm line number    */
185     int      block ;          /* current block number       */
186     int      level ;          /* current level number       */
187 } context ;
188
189 /*-----------------------------------------------------------------*/
190 /*                     symbol display information                  */
191 /*-----------------------------------------------------------------*/
192 typedef struct _dsymbol
193 {
194     char *name;
195     int  dnum;
196     int  fmt;
197     char *rs;
198 } dsymbol;
199
200
201 extern cdbrecs *recsRoot ;
202 extern context *currCtxt ;
203 extern set *modules  ; /* set of modules   */
204 extern set *functions; /* set of functions */
205 extern set *symbols  ; /* set of symbols */
206 extern set *sfrsymbols;/* set of symbols of sfr or sbit */
207 extern set *dispsymbols; /* set of displayable symbols */
208
209
210 extern char *currModName ;
211 extern char userinterrupt ;
212 extern char nointerrupt ;
213 extern short showfull ;
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 char *gc_strdup(const char *s);
220 srcLine **loadFile (char *name, int *nlines);
221
222 extern short fullname;
223 extern int srcMode;
224 extern char contsim;
225 char *searchDirsFname (char *);
226 char *getNextCmdLine(void );
227 void setCmdLine( char * );
228 void stopCommandList( void );
229
230 /* trimming functions */
231 extern char *trim_left(char *s);
232 extern char *trim_right(char *s);
233 extern char *trim(char *s);
234
235 #endif