]> git.sur5r.net Git - cc65/blob - src/dbginfo/dbginfo.h
Allow access to segment information.
[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 /*****************************************************************************/
42 /*                                   Data                                    */
43 /*****************************************************************************/
44
45
46
47 /* Data types used for addresses and line numbers. Change to "unsigned long"
48  * if you ever want to run the code on a 16-bit machine.
49  */
50 typedef unsigned cc65_line;             /* Used to store line numbers */
51 typedef unsigned cc65_addr;             /* Use to store (65xx) addresses */
52
53 /* Pointer to an opaque data structure containing information from the debug
54  * info file. Actually a handle to the data in the file.
55  */
56 typedef void* cc65_dbginfo;
57
58 /* Severity for cc65_parseerror */
59 typedef enum {
60     CC65_WARNING,
61     CC65_ERROR,
62 } cc65_error_severity;
63
64 /* Warnings/errors in cc65_read_dbginfo are passed via this struct */
65 typedef struct cc65_parseerror cc65_parseerror;
66 struct cc65_parseerror {
67     cc65_error_severity type;           /* Type of error */
68     const char*         name;           /* Name of input file */
69     cc65_line           line;           /* Error line */
70     unsigned            column;         /* Error column */
71     char                errormsg[1];    /* Error message */
72 };
73
74 /* Function that is called in case of parse errors */
75 typedef void (*cc65_errorfunc) (const struct cc65_parseerror*);
76
77 /* Line information */
78 typedef struct cc65_lineinfo cc65_lineinfo;
79 struct cc65_lineinfo {
80     unsigned            count;          /* Number of data sets that follow */
81     struct {
82         const char*     name;           /* Name of the file */
83         unsigned long   size;           /* Size of file */
84         unsigned long   mtime;          /* Modification time */
85         cc65_line       line;           /* Line number */
86         cc65_addr       start;          /* Start address for this line */
87         cc65_addr       end;            /* End address for this line */
88     }                   data[1];
89 };
90
91 /* A list of files with some information */
92 typedef struct cc65_filelist cc65_filelist;
93 struct cc65_filelist {
94     unsigned            count;          /* Number of data sets that follow */
95     struct {
96         const char*     name;           /* Name of the file */
97         unsigned long   size;           /* Size of file */
98         unsigned long   mtime;          /* Modification time */
99     }                   data[1];
100 };
101
102
103
104 /* A list of segments with some information */
105 typedef struct cc65_segmentlist cc65_segmentlist;
106 struct cc65_segmentlist {
107     unsigned            count;          /* Number of data sets that follow */
108     struct {
109         const char*     name;           /* Name of the file */
110         cc65_addr       start;          /* Start address of segment */
111         cc65_addr       end;            /* End address of segment */
112     }                   data[1];
113 };
114
115
116
117 /*****************************************************************************/
118 /*                                   Code                                    */
119 /*****************************************************************************/
120
121
122
123 cc65_dbginfo cc65_read_dbginfo (const char* filename, cc65_errorfunc errorfunc);
124 /* Parse the debug info file with the given name. On success, the function
125  * will return a pointer to an opaque cc65_dbginfo structure, that must be
126  * passed to the other functions in this module to retrieve information.
127  * errorfunc is called in case of warnings and errors. If the file cannot be
128  * read successfully, NULL is returned.
129  */
130
131 void cc65_free_dbginfo (cc65_dbginfo Handle);
132 /* Free debug information read from a file */
133
134 cc65_lineinfo* cc65_lineinfo_byaddr (cc65_dbginfo handle, unsigned long addr);
135 /* Return line information for the given address. The function returns NULL
136  * if no line information was found.
137  */
138
139 cc65_lineinfo* cc65_lineinfo_byname (cc65_dbginfo handle, const char* filename,
140                                      cc65_line line);
141 /* Return line information for a file/line number combination. The function
142  * returns NULL if no line information was found.
143  */
144
145 void cc65_free_lineinfo (cc65_dbginfo handle, cc65_lineinfo* info);
146 /* Free line info returned by one of the other functions */
147
148 cc65_filelist* cc65_get_filelist (cc65_dbginfo handle);
149 /* Return a list of all files referenced in the debug information */
150
151 void cc65_free_filelist (cc65_dbginfo handle, cc65_filelist* list);
152 /* free a file list returned by cc65_get_filelist() */
153
154 cc65_segmentlist* cc65_get_segmentlist (cc65_dbginfo handle);
155 /* Return a list of all segments referenced in the debug information */
156
157 void cc65_free_segmentlist (cc65_dbginfo handle, cc65_segmentlist* list);
158 /* Free a file list returned by cc65_get_filelist() */
159
160
161
162 /* End of dbginfo.h */
163
164 #endif
165
166
167
168