1 /*****************************************************************************/
5 /* cc65 debug info handling */
9 /* (C) 2010, Ullrich von Bassewitz */
10 /* Roemerstrasse 52 */
11 /* D-70794 Filderstadt */
12 /* EMail: uz@cc65.org */
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. */
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: */
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 */
32 /*****************************************************************************/
41 /* Allow usage from C++ */
48 /*****************************************************************************/
50 /*****************************************************************************/
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.
57 typedef unsigned cc65_line; /* Used to store line numbers */
58 typedef unsigned cc65_addr; /* Use to store (65xx) addresses */
60 /* Pointer to an opaque data structure containing information from the debug
61 * info file. Actually a handle to the data in the file.
63 typedef void* cc65_dbginfo;
65 /* Severity for cc65_parseerror */
69 } cc65_error_severity;
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 */
81 /* Function that is called in case of parse errors */
82 typedef void (*cc65_errorfunc) (const struct cc65_parseerror*);
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
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 */
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 */
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 */
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 */
124 /* Segment information.
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
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 */
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 */
146 /* Symbol information */
149 CC65_SYM_LABEL /* Some sort of address */
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 */
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 */
167 /*****************************************************************************/
169 /*****************************************************************************/
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.
181 void cc65_free_dbginfo (cc65_dbginfo Handle);
182 /* Free debug information read from a file */
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.
189 cc65_lineinfo* cc65_lineinfo_byname (cc65_dbginfo handle, const char* filename,
191 /* Return line information for a file/line number combination. The function
192 * returns NULL if no line information was found.
195 void cc65_free_lineinfo (cc65_dbginfo handle, cc65_lineinfo* info);
196 /* Free line info returned by one of the other functions */
198 cc65_sourceinfo* cc65_get_sourcelist (cc65_dbginfo handle);
199 /* Return a list of all source files */
201 void cc65_free_sourceinfo (cc65_dbginfo handle, cc65_sourceinfo* info);
202 /* Free a source info record */
204 cc65_segmentinfo* cc65_get_segmentlist (cc65_dbginfo handle);
205 /* Return a list of all segments referenced in the debug information */
207 void cc65_free_segmentinfo (cc65_dbginfo handle, cc65_segmentinfo* info);
208 /* Free a segment info record */
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.
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.
222 void cc65_free_symbolinfo (cc65_dbginfo Handle, cc65_symbolinfo* Info);
223 /* Free a symbol info record */
227 /* Allow usage from C++ */
234 /* End of dbginfo.h */