1 /*****************************************************************************/
5 /* Debug file creation for the ld65 linker */
9 /* (C) 2003-2011, 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 /*****************************************************************************/
55 /*****************************************************************************/
57 /*****************************************************************************/
61 static void AssignIds (void)
62 /* Assign the base ids for debug info output. Within each module, many of the
63 * items are addressed by ids which are actually the indices of the items in
64 * the collections. To make them unique, we must assign a unique base to each
68 /* Walk over all modules */
70 unsigned HLLSymBaseId = 0;
71 unsigned ScopeBaseId = 0;
72 unsigned SpanBaseId = 0;
73 unsigned SymBaseId = 0;
74 for (I = 0; I < CollCount (&ObjDataList); ++I) {
77 ObjData* O = CollAt (&ObjDataList, I);
79 /* Assign the module id */
83 O->HLLSymBaseId = HLLSymBaseId;
84 O->ScopeBaseId = ScopeBaseId;
85 O->SpanBaseId = SpanBaseId;
86 O->SymBaseId = SymBaseId;
88 /* Bump the base ids */
89 HLLSymBaseId += CollCount (&O->HLLDbgSyms);
90 ScopeBaseId += CollCount (&O->Scopes);
91 SpanBaseId += CollCount (&O->Spans);
92 SymBaseId += CollCount (&O->DbgSyms);
95 /* Assign the ids to the file infos */
98 /* Assign the ids to line infos */
104 void CreateDbgFile (void)
105 /* Create a debug info file */
107 /* Open the debug info file */
108 FILE* F = fopen (DbgFileName, "w");
110 Error ("Cannot create debug file `%s': %s", DbgFileName, strerror (errno));
113 /* Output version information */
114 fprintf (F, "version\tmajor=2,minor=0\n");
116 /* Output a line with the item numbers so the debug info module is able
117 * to preallocate the required memory.
121 "info\tcsym=%u,file=%u,lib=%u,line=%u,mod=%u,scope=%u,seg=%u,span=%u,sym=%u,type=%u\n",
134 /* Assign the ids to the items */
137 /* Output high level language symbols */
141 PrintDbgFileInfo (F);
143 /* Output libraries */
144 PrintDbgLibraries (F);
146 /* Output line info */
147 PrintDbgLineInfo (F);
152 /* Output the segment info */
153 PrintDbgSegments (F);
168 if (fclose (F) != 0) {
169 Error ("Error closing debug file `%s': %s", DbgFileName, strerror (errno));