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 /*****************************************************************************/
52 /*****************************************************************************/
54 /*****************************************************************************/
58 static void AssignBaseIds (void)
59 /* Assign the base ids for debug info output. Within each module, many of the
60 * items are addressed by ids which are actually the indices of the items in
61 * the collections. To make them unique, we must assign a unique base to each
67 /* Walk over all modules */
68 unsigned FileBaseId = 0;
69 unsigned SymBaseId = 0;
70 unsigned ScopeBaseId = 0;
71 for (I = 0; I < CollCount (&ObjDataList); ++I) {
74 ObjData* O = CollAt (&ObjDataList, I);
77 O->FileBaseId = FileBaseId;
78 O->SymBaseId = SymBaseId;
79 O->ScopeBaseId = ScopeBaseId;
81 /* Bump the base ids */
82 FileBaseId += CollCount (&O->Files);
83 SymBaseId += CollCount (&O->DbgSyms);
84 ScopeBaseId += CollCount (&O->Scopes);
90 void CreateDbgFile (void)
91 /* Create a debug info file */
95 /* Open the debug info file */
96 FILE* F = fopen (DbgFileName, "w");
98 Error ("Cannot create debug file `%s': %s", DbgFileName, strerror (errno));
101 /* Output version information */
102 fprintf (F, "version\tmajor=1,minor=2\n");
104 /* Assign the base ids to the modules */
108 for (I = 0; I < CollCount (&ObjDataList); ++I) {
110 /* Get this object file */
111 const ObjData* O = CollConstAt (&ObjDataList, I);
113 /* The main source file is the one at index zero */
114 const FileInfo* Source = CollConstAt (&O->Files, 0);
116 /* Output the module line */
118 "mod\tid=%u,name=\"%s\",file=%u",
123 /* Add library if any */
124 if (O->LibName != INVALID_STRING_ID) {
126 ",lib=\"%s\",mtime=0x%08lX",
127 GetString (O->LibName),
131 /* Terminate the output line */
135 /* Output the segment info */
136 PrintDbgSegments (F);
139 PrintDbgFileInfo (F);
141 /* Output line info */
142 PrintDbgLineInfo (F);
151 if (fclose (F) != 0) {
152 Error ("Error closing debug file `%s': %s", DbgFileName, strerror (errno));