]> git.sur5r.net Git - cc65/blob - src/dbginfo/dbginfo.h
Track the main scope of modules.
[cc65] / src / dbginfo / dbginfo.h
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                 dbginfo.h                                 */
4 /*                                                                           */
5 /*                         cc65 debug info handling                          */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 2010-2011, 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, sizes and line numbers. Change to "unsigned
55  * long" 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;             /* Used to store (65xx) addresses */
59 typedef unsigned cc65_size;             /* Used to store (65xx) sizes */
60
61 /* A value that is used to mark invalid ids */
62 #define CC65_INV_ID     (~0U)
63
64
65
66 /*****************************************************************************/
67 /*                             Debug info files                              */
68 /*****************************************************************************/
69
70
71
72 /* Severity for cc65_parseerror */
73 typedef enum {
74     CC65_WARNING,
75     CC65_ERROR,
76 } cc65_error_severity;
77
78 /* Warnings/errors in cc65_read_dbginfo are passed via this struct */
79 typedef struct cc65_parseerror cc65_parseerror;
80 struct cc65_parseerror {
81     cc65_error_severity type;           /* Type of error */
82     const char*         name;           /* Name of input file */
83     cc65_line           line;           /* Error line */
84     unsigned            column;         /* Error column */
85     char                errormsg[1];    /* Error message */
86 };
87
88 /* Function that is called in case of parse errors */
89 typedef void (*cc65_errorfunc) (const struct cc65_parseerror*);
90
91 /* Pointer to an opaque data structure containing information from the debug
92  * info file. Actually a handle to the data in the file.
93  */
94 typedef void* cc65_dbginfo;
95
96
97
98 cc65_dbginfo cc65_read_dbginfo (const char* filename, cc65_errorfunc errorfunc);
99 /* Parse the debug info file with the given name. On success, the function
100  * will return a pointer to an opaque cc65_dbginfo structure, that must be
101  * passed to the other functions in this module to retrieve information.
102  * errorfunc is called in case of warnings and errors. If the file cannot be
103  * read successfully, NULL is returned.
104  */
105
106 void cc65_free_dbginfo (cc65_dbginfo Handle);
107 /* Free debug information read from a file */
108
109
110
111 /*****************************************************************************/
112 /*                                 Libraries                                 */
113 /*****************************************************************************/
114
115
116
117 /* Library information */
118 typedef struct cc65_librarydata cc65_librarydata;
119 struct cc65_librarydata {
120     unsigned            library_id;     /* The internal library id */
121     const char*         library_name;   /* Name of the library */
122 };
123
124 typedef struct cc65_libraryinfo cc65_libraryinfo;
125 struct cc65_libraryinfo {
126     unsigned            count;          /* Number of data sets that follow */
127     cc65_librarydata    data[1];        /* Data sets, number is dynamic */
128 };
129
130
131
132 cc65_libraryinfo* cc65_get_librarylist (cc65_dbginfo handle);
133 /* Return a list of all libraries */
134
135 cc65_libraryinfo* cc65_libraryinfo_byid (cc65_dbginfo handle, unsigned id);
136 /* Return information about a library with a specific id. The function
137  * returns NULL if the id is invalid (no such library) and otherwise a
138  * cc65_libraryinfo structure with one entry that contains the requested
139  * library information.
140  */
141
142 void cc65_free_libraryinfo (cc65_dbginfo handle, cc65_libraryinfo* info);
143 /* Free a library info record */
144
145
146
147 /*****************************************************************************/
148 /*                                 Line info                                 */
149 /*****************************************************************************/
150
151
152
153 /* Type of line */
154 typedef enum {
155     CC65_LINE_ASM,                      /* Assembler source */
156     CC65_LINE_EXT,                      /* Externally supplied (= C) */
157     CC65_LINE_MACRO,                    /* Macro expansion */
158 } cc65_line_type;
159
160 /* Line information.
161  * Notes:
162  *   - line_end is inclusive
163  *   - output_name may be NULL if the data wasn't written to the output file
164  *     (example: bss segment)
165  *   - output_offs is invalid if there is no output_name, and may not be of
166  *     much use in case of a relocatable output file
167  */
168 typedef struct cc65_linedata cc65_linedata;
169 struct cc65_linedata {
170     unsigned            line_id;        /* Internal id of this record */
171     cc65_addr           line_start;     /* Start address for this line */
172     cc65_addr           line_end;       /* End address for this line */
173     const char*         source_name;    /* Name of the file */
174     unsigned long       source_size;    /* Size of file */
175     unsigned long       source_mtime;   /* Modification time */
176     cc65_line           source_line;    /* Line number */
177     const char*         output_name;    /* Output file */
178     unsigned long       output_offs;    /* Offset in output file */
179     cc65_line_type      line_type;      /* Type of line */
180     unsigned            count;          /* Nesting counter for macros */
181 };
182
183 typedef struct cc65_lineinfo cc65_lineinfo;
184 struct cc65_lineinfo {
185     unsigned            count;          /* Number of data sets that follow */
186     cc65_linedata       data[1];        /* Data sets, number is dynamic */
187 };
188
189
190
191 cc65_lineinfo* cc65_lineinfo_byaddr (cc65_dbginfo handle, unsigned long addr);
192 /* Return line information for the given address. The function returns NULL
193  * if no line information was found.
194  */
195
196 cc65_lineinfo* cc65_lineinfo_byname (cc65_dbginfo handle, const char* filename,
197                                      cc65_line line);
198 /* Return line information for a file/line number combination. The function
199  * returns NULL if no line information was found.
200  */
201
202 void cc65_free_lineinfo (cc65_dbginfo handle, cc65_lineinfo* info);
203 /* Free line info returned by one of the other functions */
204
205
206
207 /*****************************************************************************/
208 /*                                  Modules                                  */
209 /*****************************************************************************/
210
211
212
213 /* Module information */
214 typedef struct cc65_moduledata cc65_moduledata;
215 struct cc65_moduledata {
216     unsigned            module_id;      /* The internal module id */
217     const char*         module_name;    /* Name of the module */
218     unsigned            source_id;      /* Id of the module main file */
219     unsigned            library_id;     /* Id of the library if any */
220     unsigned            scope_id;       /* Id of the main scope */
221 };
222
223 typedef struct cc65_moduleinfo cc65_moduleinfo;
224 struct cc65_moduleinfo {
225     unsigned            count;          /* Number of data sets that follow */
226     cc65_moduledata     data[1];        /* Data sets, number is dynamic */
227 };
228
229
230
231 cc65_moduleinfo* cc65_get_modulelist (cc65_dbginfo handle);
232 /* Return a list of all modules */
233
234 cc65_moduleinfo* cc65_moduleinfo_byid (cc65_dbginfo handle, unsigned id);
235 /* Return information about a module with a specific id. The function
236  * returns NULL if the id is invalid (no such module) and otherwise a
237  * cc65_moduleinfo structure with one entry that contains the requested
238  * module information.
239  */
240
241 void cc65_free_moduleinfo (cc65_dbginfo handle, cc65_moduleinfo* info);
242 /* Free a module info record */
243
244
245
246 /*****************************************************************************/
247 /*                                   Spans                                   */
248 /*****************************************************************************/
249
250
251
252 /* Span information */
253 typedef struct cc65_spandata cc65_spandata;
254 struct cc65_spandata {
255     unsigned            span_id;        /* The internal span id */
256     cc65_addr           span_offs;      /* Offset of the span in the segment */
257     cc65_size           span_size;      /* Size of the span */
258     unsigned            segment_id;     /* Id of the segment */
259 };
260
261 typedef struct cc65_spaninfo cc65_spaninfo;
262 struct cc65_spaninfo {
263     unsigned            count;          /* Number of data sets that follow */
264     cc65_spandata       data[1];        /* Data sets, number is dynamic */
265 };
266
267
268
269 cc65_spaninfo* cc65_get_spanlist (cc65_dbginfo handle);
270 /* Return a list of all spans */
271
272 cc65_spaninfo* cc65_spaninfo_byid (cc65_dbginfo handle, unsigned id);
273 /* Return information about a span with a specific id. The function
274  * returns NULL if the id is invalid (no such span) and otherwise a
275  * cc65_spaninfo structure with one entry that contains the requested
276  * span information.
277  */
278
279 void cc65_free_spaninfo (cc65_dbginfo handle, cc65_spaninfo* info);
280 /* Free a span info record */
281
282
283
284 /*****************************************************************************/
285 /*                               Source files                                */
286 /*****************************************************************************/
287
288
289
290 /* Source file information */
291 typedef struct cc65_sourcedata cc65_sourcedata;
292 struct cc65_sourcedata {
293     unsigned            source_id;      /* The internal file id */
294     const char*         source_name;    /* Name of the file */
295     unsigned long       source_size;    /* Size of file */
296     unsigned long       source_mtime;   /* Modification time */
297 };
298
299 typedef struct cc65_sourceinfo cc65_sourceinfo;
300 struct cc65_sourceinfo {
301     unsigned            count;          /* Number of data sets that follow */
302     cc65_sourcedata     data[1];        /* Data sets, number is dynamic */
303 };
304
305
306
307 cc65_sourceinfo* cc65_get_sourcelist (cc65_dbginfo handle);
308 /* Return a list of all source files */
309
310 cc65_sourceinfo* cc65_sourceinfo_byid (cc65_dbginfo handle, unsigned id);
311 /* Return information about a source file with a specific id. The function
312  * returns NULL if the id is invalid (no such source file) and otherwise a
313  * cc65_sourceinfo structure with one entry that contains the requested
314  * source file information.
315  */
316
317 cc65_sourceinfo* cc65_sourceinfo_bymodule (cc65_dbginfo handle,
318                                            unsigned module_id);
319 /* Return information about the source files used to build a module. The
320  * function returns NULL if the module id is invalid (no such module) and
321  * otherwise a cc65_sourceinfo structure with one entry per source file.
322  */
323
324 void cc65_free_sourceinfo (cc65_dbginfo handle, cc65_sourceinfo* info);
325 /* Free a source info record */
326
327
328
329 /*****************************************************************************/
330 /*                                 Segments                                  */
331 /*****************************************************************************/
332
333
334
335 /* Segment information.
336  * Notes:
337  *   - output_name may be NULL if the data wasn't written to the output file
338  *     (example: bss segment)
339  *   - output_offs is invalid if there is no output_name, and may not be of
340  *     much use in case of a relocatable output file
341  */
342 typedef struct cc65_segmentdata cc65_segmentdata;
343 struct cc65_segmentdata {
344     unsigned            segment_id;     /* The internal segment id */
345     const char*         segment_name;   /* Name of the segment */
346     cc65_addr           segment_start;  /* Start address of segment */
347     cc65_size           segment_size;   /* Size of segment */
348     const char*         output_name;    /* Output file this seg was written to */
349     unsigned long       output_offs;    /* Offset of this seg in output file */
350 };
351
352 typedef struct cc65_segmentinfo cc65_segmentinfo;
353 struct cc65_segmentinfo {
354     unsigned            count;          /* Number of data sets that follow */
355     cc65_segmentdata    data[1];        /* Data sets, number is dynamic */
356 };
357
358
359
360 cc65_segmentinfo* cc65_get_segmentlist (cc65_dbginfo handle);
361 /* Return a list of all segments referenced in the debug information */
362
363 cc65_segmentinfo* cc65_segmentinfo_byid (cc65_dbginfo handle, unsigned id);
364 /* Return information about a segment with a specific id. The function returns
365  * NULL if the id is invalid (no such segment) and otherwise a cc65_segmentinfo
366  * structure with one entry that contains the requested segment information.
367  */
368
369 void cc65_free_segmentinfo (cc65_dbginfo handle, cc65_segmentinfo* info);
370 /* Free a segment info record */
371
372
373
374 /*****************************************************************************/
375 /*                                  Symbols                                  */
376 /*****************************************************************************/
377
378
379
380 /* Symbol information */
381 typedef enum {
382     CC65_SYM_EQUATE,
383     CC65_SYM_LABEL,                     /* Some sort of address */
384 } cc65_symbol_type;
385
386 typedef struct cc65_symboldata cc65_symboldata;
387 struct cc65_symboldata {
388     unsigned            symbol_id;      /* Id of symbol */
389     const char*         symbol_name;    /* Name of symbol */
390     cc65_symbol_type    symbol_type;    /* Type of symbol */
391     cc65_size           symbol_size;    /* Size of symbol, 0 if unknown */
392     long                symbol_value;   /* Value of symbol */
393     unsigned            segment_id;     /* If the symbol is segment relative,
394                                          * this contains the id of segment,
395                                          * otherwise CC65_INV_ID
396                                          */
397     unsigned            scope_id;       /* The scope this symbol is in */
398     unsigned            parent_id;      /* Parent symbol for cheap locals */
399 };
400
401 typedef struct cc65_symbolinfo cc65_symbolinfo;
402 struct cc65_symbolinfo {
403     unsigned            count;          /* Number of data sets that follow */
404     cc65_symboldata     data[1];        /* Data sets, number is dynamic */
405 };
406
407
408
409 cc65_symbolinfo* cc65_symbol_byid (cc65_dbginfo handle, unsigned id);
410 /* Return the symbol with a given id. The function returns NULL if no symbol
411  * with this id was found.
412  */
413
414 cc65_symbolinfo* cc65_symbol_byname (cc65_dbginfo handle, const char* name);
415 /* Return a list of symbols with a given name. The function returns NULL if
416  * no symbol with this name was found.
417  */
418
419 cc65_symbolinfo* cc65_symbol_inrange (cc65_dbginfo handle,
420                                       cc65_addr start, cc65_addr end);
421 /* Return a list of labels in the given range. end is inclusive. The function
422  * return NULL if no symbols within the given range are found. Non label
423  * symbols are ignored and not returned.
424  */
425
426 void cc65_free_symbolinfo (cc65_dbginfo Handle, cc65_symbolinfo* Info);
427 /* Free a symbol info record */
428
429
430
431 /*****************************************************************************/
432 /*                                  Scopes                                   */
433 /*****************************************************************************/
434
435
436
437 /* Scope information */
438 typedef enum {
439     CC65_SCOPE_GLOBAL,                  /* Global scope */
440     CC65_SCOPE_MODULE,                  /* Module scope */
441     CC65_SCOPE_SCOPE,                   /* .PROC/.SCOPE */
442     CC65_SCOPE_STRUCT,                  /* .STRUCT */
443     CC65_SCOPE_ENUM,                    /* .ENUM */
444 } cc65_scope_type;
445
446 typedef struct cc65_scopedata cc65_scopedata;
447 struct cc65_scopedata {
448     unsigned            scope_id;       /* Id of scope */
449     const char*         scope_name;     /* Name of scope */
450     cc65_scope_type     scope_type;     /* Type of scope */
451     cc65_size           scope_size;     /* Size of scope, 0 if unknown */
452     unsigned            scope_parent;   /* Id of parent scope */
453     unsigned            symbol_id;      /* Id of scope symbol if any */
454     unsigned            module_id;      /* Id of the module */
455 };
456
457 typedef struct cc65_scopeinfo cc65_scopeinfo;
458 struct cc65_scopeinfo {
459     unsigned            count;          /* Number of data sets that follow */
460     cc65_scopedata      data[1];        /* Data sets, number is dynamic */
461 };
462
463
464
465 cc65_scopeinfo* cc65_scope_byid (cc65_dbginfo handle, unsigned id);
466 /* Return the scope with a given id. The function returns NULL if no scope
467  * with this id was found.
468  */
469
470 cc65_scopeinfo* cc65_scope_bymodule (cc65_dbginfo handle, unsigned module_id);
471 /* Return the list of scopes for one module. The function returns NULL if no
472  * scope with the given id was found.
473  */
474
475 void cc65_free_scopeinfo (cc65_dbginfo Handle, cc65_scopeinfo* Info);
476 /* Free a scope info record */
477
478
479
480 /* Allow usage from C++ */
481 #ifdef __cplusplus
482 }
483 #endif
484
485
486
487 /* End of dbginfo.h */
488 #endif
489
490
491