]> git.sur5r.net Git - cc65/blob - src/dbginfo/dbginfo.h
New function cc65_symbol_inrange. Fixed an error in cc65_symbol_byname.
[cc65] / src / dbginfo / dbginfo.h
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                 dbginfo.h                                 */
4 /*                                                                           */
5 /*                         cc65 debug info handling                          */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 2010,      Ullrich von Bassewitz                                      */
10 /*                Roemerstrasse 52                                           */
11 /*                D-70794 Filderstadt                                        */
12 /* EMail:         uz@cc65.org                                                */
13 /*                                                                           */
14 /*                                                                           */
15 /* This software is provided 'as-is', without any expressed or implied       */
16 /* warranty.  In no event will the authors be held liable for any damages    */
17 /* arising from the use of this software.                                    */
18 /*                                                                           */
19 /* Permission is granted to anyone to use this software for any purpose,     */
20 /* including commercial applications, and to alter it and redistribute it    */
21 /* freely, subject to the following restrictions:                            */
22 /*                                                                           */
23 /* 1. The origin of this software must not be misrepresented; you must not   */
24 /*    claim that you wrote the original software. If you use this software   */
25 /*    in a product, an acknowledgment in the product documentation would be  */
26 /*    appreciated but is not required.                                       */
27 /* 2. Altered source versions must be plainly marked as such, and must not   */
28 /*    be misrepresented as being the original software.                      */
29 /* 3. This notice may not be removed or altered from any source              */
30 /*    distribution.                                                          */
31 /*                                                                           */
32 /*****************************************************************************/
33
34
35
36 #ifndef DBGINFO_H
37 #define DBGINFO_H
38
39
40
41 /* Allow usage from C++ */
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45
46
47
48 /*****************************************************************************/
49 /*                                   Data                                    */
50 /*****************************************************************************/
51
52
53
54 /* Data types used for addresses and line numbers. Change to "unsigned long"
55  * if you ever want to run the code on a 16-bit machine.
56  */
57 typedef unsigned cc65_line;             /* Used to store line numbers */
58 typedef unsigned cc65_addr;             /* Use to store (65xx) addresses */
59
60 /* Pointer to an opaque data structure containing information from the debug
61  * info file. Actually a handle to the data in the file.
62  */
63 typedef void* cc65_dbginfo;
64
65 /* Severity for cc65_parseerror */
66 typedef enum {
67     CC65_WARNING,
68     CC65_ERROR,
69 } cc65_error_severity;
70
71 /* Warnings/errors in cc65_read_dbginfo are passed via this struct */
72 typedef struct cc65_parseerror cc65_parseerror;
73 struct cc65_parseerror {
74     cc65_error_severity type;           /* Type of error */
75     const char*         name;           /* Name of input file */
76     cc65_line           line;           /* Error line */
77     unsigned            column;         /* Error column */
78     char                errormsg[1];    /* Error message */
79 };
80
81 /* Function that is called in case of parse errors */
82 typedef void (*cc65_errorfunc) (const struct cc65_parseerror*);
83
84 /* Line information.
85  * Notes:
86  *   - line_end is inclusive
87  *   - output_name may be NULL if the data wasn't written to the output file
88  *     (example: bss segment)
89  *   - output_offs is invalid if there is no output_name, and may not be of
90  *     much use in case of a relocatable output file
91  */
92 typedef struct cc65_linedata cc65_linedata;
93 struct cc65_linedata {
94     const char*         source_name;    /* Name of the file */
95     unsigned long       source_size;    /* Size of file */
96     unsigned long       source_mtime;   /* Modification time */
97     cc65_line           source_line;    /* Line number */
98     cc65_addr           line_start;     /* Start address for this line */
99     cc65_addr           line_end;       /* End address for this line */
100     const char*         output_name;    /* Output file */
101     unsigned long       output_offs;    /* Offset in output file */
102 };
103
104 typedef struct cc65_lineinfo cc65_lineinfo;
105 struct cc65_lineinfo {
106     unsigned            count;          /* Number of data sets that follow */
107     cc65_linedata       data[1];        /* Data sets, number is dynamic */
108 };
109
110 /* Source file information */
111 typedef struct cc65_sourcedata cc65_sourcedata;
112 struct cc65_sourcedata {
113     const char*         source_name;    /* Name of the file */
114     unsigned long       source_size;    /* Size of file */
115     unsigned long       source_mtime;   /* Modification time */
116 };
117
118 typedef struct cc65_sourceinfo cc65_sourceinfo;
119 struct cc65_sourceinfo {
120     unsigned            count;          /* Number of data sets that follow */
121     cc65_sourcedata     data[1];        /* Data sets, number is dynamic */
122 };
123
124 /* Segment information.
125  * Notes:
126  *   - output_name may be NULL if the data wasn't written to the output file
127  *     (example: bss segment)
128  *   - output_offs is invalid if there is no output_name, and may not be of
129  *     much use in case of a relocatable output file
130  */
131 typedef struct cc65_segmentdata cc65_segmentdata;
132 struct cc65_segmentdata {
133     const char*         segment_name;   /* Name of the segment */
134     cc65_addr           segment_start;  /* Start address of segment */
135     cc65_addr           segment_size;   /* Size of segment */
136     const char*         output_name;    /* Output file this seg was written to */
137     unsigned long       output_offs;    /* Offset of this seg in output file */
138 };
139
140 typedef struct cc65_segmentinfo cc65_segmentinfo;
141 struct cc65_segmentinfo {
142     unsigned            count;          /* Number of data sets that follow */
143     cc65_segmentdata    data[1];        /* Data sets, number is dynamic */
144 };
145
146 /* Symbol information */
147 typedef enum {
148     CC65_SYM_EQUATE,
149     CC65_SYM_LABEL                      /* Some sort of address */
150 } cc65_symbol_type;
151
152 typedef struct cc65_symboldata cc65_symboldata;
153 struct cc65_symboldata {
154     const char*         symbol_name;    /* Name of symbol */
155     cc65_symbol_type    symbol_type;    /* Type of symbol */
156     long                symbol_value;   /* Value of symbol */
157 };
158
159 typedef struct cc65_symbolinfo cc65_symbolinfo;
160 struct cc65_symbolinfo {
161     unsigned            count;          /* Number of data sets that follow */
162     cc65_symboldata     data[1];        /* Data sets, number is dynamic */
163 };
164
165
166
167 /*****************************************************************************/
168 /*                                   Code                                    */
169 /*****************************************************************************/
170
171
172
173 cc65_dbginfo cc65_read_dbginfo (const char* filename, cc65_errorfunc errorfunc);
174 /* Parse the debug info file with the given name. On success, the function
175  * will return a pointer to an opaque cc65_dbginfo structure, that must be
176  * passed to the other functions in this module to retrieve information.
177  * errorfunc is called in case of warnings and errors. If the file cannot be
178  * read successfully, NULL is returned.
179  */
180
181 void cc65_free_dbginfo (cc65_dbginfo Handle);
182 /* Free debug information read from a file */
183
184 cc65_lineinfo* cc65_lineinfo_byaddr (cc65_dbginfo handle, unsigned long addr);
185 /* Return line information for the given address. The function returns NULL
186  * if no line information was found.
187  */
188
189 cc65_lineinfo* cc65_lineinfo_byname (cc65_dbginfo handle, const char* filename,
190                                      cc65_line line);
191 /* Return line information for a file/line number combination. The function
192  * returns NULL if no line information was found.
193  */
194
195 void cc65_free_lineinfo (cc65_dbginfo handle, cc65_lineinfo* info);
196 /* Free line info returned by one of the other functions */
197
198 cc65_sourceinfo* cc65_get_sourcelist (cc65_dbginfo handle);
199 /* Return a list of all source files */
200
201 void cc65_free_sourceinfo (cc65_dbginfo handle, cc65_sourceinfo* info);
202 /* Free a source info record */
203
204 cc65_segmentinfo* cc65_get_segmentlist (cc65_dbginfo handle);
205 /* Return a list of all segments referenced in the debug information */
206
207 void cc65_free_segmentinfo (cc65_dbginfo handle, cc65_segmentinfo* info);
208 /* Free a segment info record */
209
210 cc65_symbolinfo* cc65_symbol_byname (cc65_dbginfo handle, const char* name);
211 /* Return a list of symbols with a given name. The function returns NULL if
212  * no symbol with this name was found.
213  */
214
215 cc65_symbolinfo* cc65_symbol_inrange (cc65_dbginfo handle,
216                                       cc65_addr start, cc65_addr end);
217 /* Return a list of labels in the given range. end is inclusive. The function
218  * return NULL if no symbols withing the given range are found. Non label
219  * symbols are ignored and not returned.
220  */
221
222 void cc65_free_symbolinfo (cc65_dbginfo Handle, cc65_symbolinfo* Info);
223 /* Free a symbol info record */
224
225
226
227 /* Allow usage from C++ */
228 #ifdef __cplusplus
229 }
230 #endif
231
232
233
234 /* End of dbginfo.h */
235 #endif
236
237
238