Files
cc65/src/ld65/dbgfile.c
uz 1797235794 Read and manage additional line information for symbols.
git-svn-id: svn://svn.cc65.org/cc65/trunk@5215 b7a2c559-68d2-44c3-8de9-860c34a00d81
2011-08-18 16:27:18 +00:00

161 lines
5.2 KiB
C

/*****************************************************************************/
/* */
/* dbgfile.c */
/* */
/* Debug file creation for the ld65 linker */
/* */
/* */
/* */
/* (C) 2003-2011, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
/* warranty. In no event will the authors be held liable for any damages */
/* arising from the use of this software. */
/* */
/* Permission is granted to anyone to use this software for any purpose, */
/* including commercial applications, and to alter it and redistribute it */
/* freely, subject to the following restrictions: */
/* */
/* 1. The origin of this software must not be misrepresented; you must not */
/* claim that you wrote the original software. If you use this software */
/* in a product, an acknowledgment in the product documentation would be */
/* appreciated but is not required. */
/* 2. Altered source versions must be plainly marked as such, and must not */
/* be misrepresented as being the original software. */
/* 3. This notice may not be removed or altered from any source */
/* distribution. */
/* */
/*****************************************************************************/
#include <stdio.h>
#include <string.h>
#include <errno.h>
/* ld65 */
#include "dbgfile.h"
#include "dbgsyms.h"
#include "error.h"
#include "fileinfo.h"
#include "global.h"
#include "library.h"
#include "lineinfo.h"
#include "scopes.h"
#include "segments.h"
#include "span.h"
/*****************************************************************************/
/* Code */
/*****************************************************************************/
static void AssignIds (void)
/* Assign the base ids for debug info output. Within each module, many of the
* items are addressed by ids which are actually the indices of the items in
* the collections. To make them unique, we must assign a unique base to each
* range.
*/
{
/* Walk over all modules */
unsigned I;
unsigned ScopeBaseId = 0;
unsigned SpanBaseId = 0;
unsigned SymBaseId = 0;
for (I = 0; I < CollCount (&ObjDataList); ++I) {
/* Get this module */
ObjData* O = CollAt (&ObjDataList, I);
/* Assign the module id */
O->Id = I;
/* Assign base ids */
O->ScopeBaseId = ScopeBaseId;
O->SpanBaseId = SpanBaseId;
O->SymBaseId = SymBaseId;
/* Bump the base ids */
ScopeBaseId += CollCount (&O->Scopes);
SpanBaseId += CollCount (&O->Spans);
SymBaseId += CollCount (&O->DbgSyms);
}
/* Assign the ids to the file infos */
AssignFileInfoIds ();
/* Assign the ids to line infos */
AssignLineInfoIds ();
}
void CreateDbgFile (void)
/* Create a debug info file */
{
/* Open the debug info file */
FILE* F = fopen (DbgFileName, "w");
if (F == 0) {
Error ("Cannot create debug file `%s': %s", DbgFileName, strerror (errno));
}
/* Output version information */
fprintf (F, "version\tmajor=2,minor=0\n");
/* Output a line with the item numbers so the debug info module is able
* to preallocate the required memory.
*/
fprintf (
F,
"info\tfile=%u,lib=%u,mod=%u,scope=%u,seg=%u,span=%u\n",
FileInfoCount (),
LibraryCount (),
ObjDataCount (),
ScopeCount (),
SegmentCount (),
SpanCount ()
);
/* Assign the ids to the items */
AssignIds ();
/* Output libraries */
PrintDbgLibraries (F);
/* Output modules */
PrintDbgModules (F);
/* Output the segment info */
PrintDbgSegments (F);
/* Output files */
PrintDbgFileInfo (F);
/* Output line info */
PrintDbgLineInfo (F);
/* Output spans */
PrintDbgSpans (F);
/* Output symbols */
PrintDbgSyms (F);
/* Output scopes */
PrintDbgScopes (F);
/* Close the file */
if (fclose (F) != 0) {
Error ("Error closing debug file `%s': %s", DbgFileName, strerror (errno));
}
}