]> git.sur5r.net Git - cc65/blob - src/ld65/mapfile.c
More debug infos
[cc65] / src / ld65 / mapfile.c
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                 mapfile.c                                 */
4 /*                                                                           */
5 /*                   Map file creation for the ld65 linker                   */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 1998-2003 Ullrich von Bassewitz                                       */
10 /*               Römerstrasse 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 "config.h"
42 #include "dbginfo.h"
43 #include "dbgsyms.h"
44 #include "exports.h"
45 #include "global.h"
46 #include "error.h"
47 #include "mapfile.h"
48 #include "objdata.h"
49 #include "segments.h"
50 #include "spool.h"
51
52
53
54 /*****************************************************************************/
55 /*                                   Code                                    */
56 /*****************************************************************************/
57
58
59
60 void CreateMapFile (void)
61 /* Create a map file */
62 {
63     unsigned I;
64
65     /* Open the map file */
66     FILE* F = fopen (MapFileName, "w");
67     if (F == 0) {
68         Error ("Cannot create map file `%s': %s", MapFileName, strerror (errno));
69     }
70
71     /* Write a modules list */
72     fprintf (F, "Modules list:\n"
73                 "-------------\n");
74     for (I = 0; I < CollCount (&ObjDataList); ++I) {
75
76         unsigned J;
77
78         /* Get the object file */
79         const ObjData* O = CollConstAt (&ObjDataList, I);
80
81         /* Output the data */
82         if (O->LibName != INVALID_STRING_ID) {
83             /* The file is from a library */
84             fprintf (F, "%s(%s):\n", GetString (O->LibName), GetObjFileName (O));
85         } else {
86             fprintf (F, "%s:\n", GetObjFileName (O));
87         }
88         for (J = 0; J < O->SectionCount; ++J) {
89             const Section* S = O->Sections [J];
90             /* Don't include zero sized sections if not explicitly
91              * requested
92              */
93             if (VerboseMap || S->Size > 0) {
94                 fprintf (F, "    %-15s   Offs = %06lX   Size = %06lX\n",
95                          GetString (S->Seg->Name), S->Offs, S->Size);
96             }
97         }
98     }
99
100     /* Write the segment list */
101     fprintf (F, "\n\n"
102                 "Segment list:\n"
103                 "-------------\n");
104     PrintSegmentMap (F);
105
106     /* Write the exports list */
107     fprintf (F, "\n\n"
108                 "Exports list:\n"
109                 "-------------\n");
110     PrintExportMap (F);
111
112     /* Write the imports list */
113     fprintf (F, "\n\n"
114                 "Imports list:\n"
115                 "-------------\n");
116     PrintImportMap (F);
117
118     /* Close the file */
119     if (fclose (F) != 0) {
120         Error ("Error closing map file `%s': %s", MapFileName, strerror (errno));
121     }
122 }
123
124
125
126 void CreateLabelFile (void)
127 /* Create a label file */
128 {
129     unsigned I;
130
131     /* Open the label file */
132     FILE* F = fopen (LabelFileName, "w");
133     if (F == 0) {
134         Error ("Cannot create label file `%s': %s", LabelFileName, strerror (errno));
135     }
136
137     /* Print the labels for the export symbols */
138     PrintExportLabels (F);
139
140     /* Create labels from all modules we have linked into the output file */
141     for (I = 0; I < CollCount (&ObjDataList); ++I) {
142
143         /* Get the object file */
144         ObjData* O = CollAtUnchecked (&ObjDataList, I);
145
146         /* Output the labels */
147         PrintDbgSymLabels (O, F);
148     }
149
150     /* Close the file */
151     if (fclose (F) != 0) {
152         Error ("Error closing label file `%s': %s", LabelFileName, strerror (errno));
153     }
154 }
155
156
157
158 void CreateDbgFile (void)
159 /* Create a debug info file */
160 {
161     unsigned I;
162
163     /* Open the debug info file */
164     FILE* F = fopen (DbgFileName, "w");
165     if (F == 0) {
166         Error ("Cannot create debug file `%s': %s", DbgFileName, strerror (errno));
167     }
168
169     /* Print line infos from all modules we have linked into the output file */
170     for (I = 0; I < CollCount (&ObjDataList); ++I) {
171
172         /* Get the object file */
173         ObjData* O = CollAtUnchecked (&ObjDataList, I);
174
175         /* Output debug info */
176         PrintDbgInfo (O, F);
177         PrintDbgSyms (O, F);
178     }
179
180     /* Close the file */
181     if (fclose (F) != 0) {
182         Error ("Error closing debug file `%s': %s", DbgFileName, strerror (errno));
183     }
184 }
185
186
187