]> git.sur5r.net Git - cc65/blob - src/ld65/dbgfile.c
Debug info: Make file info ids continous. Output modules that use a file.
[cc65] / src / ld65 / dbgfile.c
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                 dbgfile.c                                 */
4 /*                                                                           */
5 /*                  Debug file creation for the ld65 linker                  */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 2003-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 #include <stdio.h>
37 #include <string.h>
38 #include <errno.h>
39
40 /* ld65 */
41 #include "dbgfile.h"
42 #include "dbgsyms.h"
43 #include "error.h"
44 #include "fileinfo.h"
45 #include "global.h"
46 #include "library.h"
47 #include "lineinfo.h"
48 #include "scopes.h"
49 #include "segments.h"
50
51
52
53 /*****************************************************************************/
54 /*                                   Code                                    */
55 /*****************************************************************************/
56
57
58
59 static void AssignIds (void)
60 /* Assign the base ids for debug info output. Within each module, many of the
61  * items are addressed by ids which are actually the indices of the items in
62  * the collections. To make them unique, we must assign a unique base to each
63  * range.
64  */
65 {
66     /* Walk over all modules */
67     unsigned I;
68     unsigned SymBaseId   = 0;
69     unsigned ScopeBaseId = 0;
70     for (I = 0; I < CollCount (&ObjDataList); ++I) {
71
72         /* Get this module */
73         ObjData* O = CollAt (&ObjDataList, I);
74
75         /* Assign the module id */
76         O->Id = I;
77
78         /* Assign base ids */
79         O->SymBaseId   = SymBaseId;
80         O->ScopeBaseId = ScopeBaseId;
81
82         /* Bump the base ids */
83         SymBaseId     += CollCount (&O->DbgSyms);
84         ScopeBaseId   += CollCount (&O->Scopes);
85     }         
86
87     /* Assign the ids to the file infos */
88     AssignFileInfoIds ();
89 }
90
91
92
93 void CreateDbgFile (void)
94 /* Create a debug info file */
95 {
96     /* Open the debug info file */
97     FILE* F = fopen (DbgFileName, "w");
98     if (F == 0) {
99         Error ("Cannot create debug file `%s': %s", DbgFileName, strerror (errno));
100     }
101
102     /* Output version information */
103     fprintf (F, "version\tmajor=1,minor=2\n");
104
105     /* Assign the ids to the items */
106     AssignIds ();
107
108     /* Output libraries */
109     PrintDbgLibraries (F);
110
111     /* Output modules */
112     PrintDbgModules (F);
113
114     /* Output the segment info */
115     PrintDbgSegments (F);
116
117     /* Output files */
118     PrintDbgFileInfo (F);
119
120     /* Output line info */
121     PrintDbgLineInfo (F);
122
123     /* Output symbols */
124     PrintDbgSyms (F);
125
126     /* Output scopes */
127     PrintDbgScopes (F);
128
129     /* Close the file */
130     if (fclose (F) != 0) {
131         Error ("Error closing debug file `%s': %s", DbgFileName, strerror (errno));
132     }
133 }
134
135
136