]> git.sur5r.net Git - cc65/blob - src/dbginfo/dbginfo.h
Shortened some of the function names.
[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 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 const 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 const cc65_libraryinfo* cc65_get_librarylist (cc65_dbginfo handle);
133 /* Return a list of all libraries */
134
135 const cc65_libraryinfo* cc65_library_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, const 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 typedef struct cc65_linedata cc65_linedata;
162 struct cc65_linedata {
163     unsigned            line_id;        /* Internal id of this record */
164     unsigned            source_id;      /* Id of the source file */
165     cc65_line           source_line;    /* Line number */
166     cc65_line_type      line_type;      /* Type of line */
167     unsigned            count;          /* Nesting counter for macros */
168 };
169
170 typedef struct cc65_lineinfo cc65_lineinfo;
171 struct cc65_lineinfo {
172     unsigned            count;          /* Number of data sets that follow */
173     cc65_linedata       data[1];        /* Data sets, number is dynamic */
174 };
175
176
177
178 const cc65_lineinfo* cc65_line_bynumber (cc65_dbginfo handle,
179                                          unsigned source_id,
180                                          cc65_line line);
181 /* Return line information for a source file/line number combination. The
182  * function returns NULL if no line information was found.
183  */
184
185 void cc65_free_lineinfo (cc65_dbginfo handle, const cc65_lineinfo* info);
186 /* Free line info returned by one of the other functions */
187
188
189
190 /*****************************************************************************/
191 /*                                  Modules                                  */
192 /*****************************************************************************/
193
194
195
196 /* Module information */
197 typedef struct cc65_moduledata cc65_moduledata;
198 struct cc65_moduledata {
199     unsigned            module_id;      /* The internal module id */
200     const char*         module_name;    /* Name of the module */
201     unsigned            source_id;      /* Id of the module main file */
202     unsigned            library_id;     /* Id of the library if any */
203     unsigned            scope_id;       /* Id of the main scope */
204 };
205
206 typedef struct cc65_moduleinfo cc65_moduleinfo;
207 struct cc65_moduleinfo {
208     unsigned            count;          /* Number of data sets that follow */
209     cc65_moduledata     data[1];        /* Data sets, number is dynamic */
210 };
211
212
213
214 const cc65_moduleinfo* cc65_get_modulelist (cc65_dbginfo handle);
215 /* Return a list of all modules */
216
217 const cc65_moduleinfo* cc65_module_byid (cc65_dbginfo handle, unsigned id);
218 /* Return information about a module with a specific id. The function
219  * returns NULL if the id is invalid (no such module) and otherwise a
220  * cc65_moduleinfo structure with one entry that contains the requested
221  * module information.
222  */
223
224 void cc65_free_moduleinfo (cc65_dbginfo handle, const cc65_moduleinfo* info);
225 /* Free a module info record */
226
227
228
229 /*****************************************************************************/
230 /*                                   Spans                                   */
231 /*****************************************************************************/
232
233
234
235 /* Span information */
236 typedef struct cc65_spandata cc65_spandata;
237 struct cc65_spandata {
238     unsigned            span_id;        /* The internal span id */
239     cc65_addr           span_start;     /* Start of the span */
240     cc65_addr           span_end;       /* End of the span (inclusive!) */
241     unsigned            segment_id;     /* Id of the segment */
242 };
243
244 typedef struct cc65_spaninfo cc65_spaninfo;
245 struct cc65_spaninfo {
246     unsigned            count;          /* Number of data sets that follow */
247     cc65_spandata       data[1];        /* Data sets, number is dynamic */
248 };
249
250
251
252 const cc65_spaninfo* cc65_get_spanlist (cc65_dbginfo handle);
253 /* Return a list of all spans. BEWARE: Large! */
254
255 const cc65_spaninfo* cc65_span_byid (cc65_dbginfo handle, unsigned id);
256 /* Return information about a span with a specific id. The function
257  * returns NULL if the id is invalid (no such span) and otherwise a
258  * cc65_spaninfo structure with one entry that contains the requested
259  * span information.
260  */
261
262 const cc65_spaninfo* cc65_span_byaddr (cc65_dbginfo handle,
263                                        unsigned long addr);
264 /* Return span information for the given address. The function returns NULL
265  * if no spans were found for this address.
266  */
267
268 const cc65_spaninfo* cc65_span_byline (cc65_dbginfo handle, unsigned line_id);
269 /* Return span information for the given source line. The function returns NULL
270  * if the line id is invalid, otherwise the spans for this line (possibly zero).
271  */
272
273 const cc65_spaninfo* cc65_span_byscope (cc65_dbginfo handle, unsigned scope_id);
274 /* Return span information for the given scope. The function returns NULL if
275  * the scope id is invalid, otherwise the spans for this scope (possibly zero).
276  */
277
278 void cc65_free_spaninfo (cc65_dbginfo handle, const cc65_spaninfo* info);
279 /* Free a span info record */
280
281
282
283 /*****************************************************************************/
284 /*                               Source files                                */
285 /*****************************************************************************/
286
287
288
289 /* Source file information */
290 typedef struct cc65_sourcedata cc65_sourcedata;
291 struct cc65_sourcedata {
292     unsigned            source_id;      /* The internal file id */
293     const char*         source_name;    /* Name of the file */
294     unsigned long       source_size;    /* Size of file */
295     unsigned long       source_mtime;   /* Modification time */
296 };
297
298 typedef struct cc65_sourceinfo cc65_sourceinfo;
299 struct cc65_sourceinfo {
300     unsigned            count;          /* Number of data sets that follow */
301     cc65_sourcedata     data[1];        /* Data sets, number is dynamic */
302 };
303
304
305
306 const cc65_sourceinfo* cc65_get_sourcelist (cc65_dbginfo handle);
307 /* Return a list of all source files */
308
309 const cc65_sourceinfo* cc65_source_byid (cc65_dbginfo handle, unsigned id);
310 /* Return information about a source file with a specific id. The function
311  * returns NULL if the id is invalid (no such source file) and otherwise a
312  * cc65_sourceinfo structure with one entry that contains the requested
313  * source file information.
314  */
315
316 const cc65_sourceinfo* cc65_source_bymodule (cc65_dbginfo handle,
317                                              unsigned module_id);
318 /* Return information about the source files used to build a module. The
319  * function returns NULL if the module id is invalid (no such module) and
320  * otherwise a cc65_sourceinfo structure with one entry per source file.
321  */
322
323 void cc65_free_sourceinfo (cc65_dbginfo handle, const cc65_sourceinfo* info);
324 /* Free a source info record */
325
326
327
328 /*****************************************************************************/
329 /*                                 Segments                                  */
330 /*****************************************************************************/
331
332
333
334 /* Segment information.
335  * Notes:
336  *   - output_name may be NULL if the data wasn't written to the output file
337  *     (example: bss segment)
338  *   - output_offs is invalid if there is no output_name, and may not be of
339  *     much use in case of a relocatable output file
340  */
341 typedef struct cc65_segmentdata cc65_segmentdata;
342 struct cc65_segmentdata {
343     unsigned            segment_id;     /* The internal segment id */
344     const char*         segment_name;   /* Name of the segment */
345     cc65_addr           segment_start;  /* Start address of segment */
346     cc65_size           segment_size;   /* Size of segment */
347     const char*         output_name;    /* Output file this seg was written to */
348     unsigned long       output_offs;    /* Offset of this seg in output file */
349 };
350
351 typedef struct cc65_segmentinfo cc65_segmentinfo;
352 struct cc65_segmentinfo {
353     unsigned            count;          /* Number of data sets that follow */
354     cc65_segmentdata    data[1];        /* Data sets, number is dynamic */
355 };
356
357
358
359 const cc65_segmentinfo* cc65_get_segmentlist (cc65_dbginfo handle);
360 /* Return a list of all segments referenced in the debug information */
361
362 const cc65_segmentinfo* cc65_segment_byid (cc65_dbginfo handle, unsigned id);
363 /* Return information about a segment with a specific id. The function returns
364  * NULL if the id is invalid (no such segment) and otherwise a cc65_segmentinfo
365  * structure with one entry that contains the requested segment information.
366  */
367
368 const cc65_segmentinfo* cc65_segment_byname (cc65_dbginfo handle,
369                                              const char* name);
370 /* Return information about a segment with a specific name. The function
371  * returns NULL if no segment with this name exists and otherwise a
372  * cc65_segmentinfo structure with one entry that contains the requested
373  * information.
374  */
375
376 void cc65_free_segmentinfo (cc65_dbginfo handle, const cc65_segmentinfo* info);
377 /* Free a segment info record */
378
379
380
381 /*****************************************************************************/
382 /*                                  Symbols                                  */
383 /*****************************************************************************/
384
385
386
387 /* Symbol information */
388 typedef enum {
389     CC65_SYM_EQUATE,
390     CC65_SYM_LABEL,                     /* Some sort of address */
391 } cc65_symbol_type;
392
393 /* Notes:
394  *  - If the symbol is segment relative, the segment id gives segment
395  *    information, otherwise it contains CC65_INV_ID.
396  *  - If export_id is valid (not CC65_INV_ID), the symbol is an import and
397  *    export_id allows to retrieve the corresponding export. The fields
398  *    symbol_value and segment_id are taken from the export, since imports
399  *    have no value or segments by itself. symbol_type and symbol_size are
400  *    more or less unusable because they don't have a meaning for imports.
401  *  - For normal symbols (not cheap locals) parent_id contains CC65_INV_ID.
402  */
403 typedef struct cc65_symboldata cc65_symboldata;
404 struct cc65_symboldata {
405     unsigned            symbol_id;      /* Id of symbol */
406     const char*         symbol_name;    /* Name of symbol */
407     cc65_symbol_type    symbol_type;    /* Type of symbol */
408     cc65_size           symbol_size;    /* Size of symbol, 0 if unknown */
409     long                symbol_value;   /* Value of symbol */
410     unsigned            export_id;      /* For imports: Matching export */
411     unsigned            segment_id;     /* Id of segment if any */
412     unsigned            scope_id;       /* The scope this symbol is in */
413     unsigned            parent_id;      /* Parent symbol for cheap locals */
414 };
415
416 typedef struct cc65_symbolinfo cc65_symbolinfo;
417 struct cc65_symbolinfo {
418     unsigned            count;          /* Number of data sets that follow */
419     cc65_symboldata     data[1];        /* Data sets, number is dynamic */
420 };
421
422
423
424 const cc65_symbolinfo* cc65_symbol_byid (cc65_dbginfo handle, unsigned id);
425 /* Return the symbol with a given id. The function returns NULL if no symbol
426  * with this id was found.
427  */
428
429 const cc65_symbolinfo* cc65_symbol_byname (cc65_dbginfo handle, const char* name);
430 /* Return a list of symbols with a given name. The function returns NULL if
431  * no symbol with this name was found.
432  */
433
434 const cc65_symbolinfo* cc65_symbol_inrange (cc65_dbginfo handle,
435                                             cc65_addr start, cc65_addr end);
436 /* Return a list of labels in the given range. end is inclusive. The function
437  * return NULL if no symbols within the given range are found. Non label
438  * symbols are ignored and not returned.
439  */
440
441 void cc65_free_symbolinfo (cc65_dbginfo Handle, const cc65_symbolinfo* Info);
442 /* Free a symbol info record */
443
444
445
446 /*****************************************************************************/
447 /*                                  Scopes                                   */
448 /*****************************************************************************/
449
450
451
452 /* Scope information */
453 typedef enum {
454     CC65_SCOPE_GLOBAL,                  /* Global scope */
455     CC65_SCOPE_MODULE,                  /* Module scope */
456     CC65_SCOPE_SCOPE,                   /* .PROC/.SCOPE */
457     CC65_SCOPE_STRUCT,                  /* .STRUCT */
458     CC65_SCOPE_ENUM,                    /* .ENUM */
459 } cc65_scope_type;
460
461 typedef struct cc65_scopedata cc65_scopedata;
462 struct cc65_scopedata {
463     unsigned            scope_id;       /* Id of scope */
464     const char*         scope_name;     /* Name of scope */
465     cc65_scope_type     scope_type;     /* Type of scope */
466     cc65_size           scope_size;     /* Size of scope, 0 if unknown */
467     unsigned            parent_id;      /* Id of parent scope */
468     unsigned            symbol_id;      /* Id of scope symbol if any */
469     unsigned            module_id;      /* Id of the module */
470 };
471
472 typedef struct cc65_scopeinfo cc65_scopeinfo;
473 struct cc65_scopeinfo {
474     unsigned            count;          /* Number of data sets that follow */
475     cc65_scopedata      data[1];        /* Data sets, number is dynamic */
476 };
477
478
479
480 const cc65_scopeinfo* cc65_get_scopelist (cc65_dbginfo handle);
481 /* Return a list of all scopes in the debug information */
482
483 const cc65_scopeinfo* cc65_scope_byid (cc65_dbginfo handle, unsigned id);
484 /* Return the scope with a given id. The function returns NULL if no scope
485  * with this id was found.
486  */
487
488 const cc65_scopeinfo* cc65_scope_bymodule (cc65_dbginfo handle, unsigned module_id);
489 /* Return the list of scopes for one module. The function returns NULL if no
490  * scope with the given id was found.
491  */
492
493 void cc65_free_scopeinfo (cc65_dbginfo Handle, const cc65_scopeinfo* Info);
494 /* Free a scope info record */
495
496
497
498 /* Allow usage from C++ */
499 #ifdef __cplusplus
500 }
501 #endif
502
503
504
505 /* End of dbginfo.h */
506 #endif
507
508
509