1
0
mirror of https://github.com/cc65/cc65.git synced 2025-01-26 17:36:57 +00:00

Rearrange debug info output. Add scopes to the debug info.

git-svn-id: svn://svn.cc65.org/cc65/trunk@5117 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
uz 2011-08-04 15:58:54 +00:00
parent 871873b1ac
commit 2f75733e43
13 changed files with 164 additions and 220 deletions

View File

@ -39,10 +39,12 @@
/* ld65 */
#include "dbgfile.h"
#include "dbginfo.h"
#include "dbgsyms.h"
#include "error.h"
#include "fileinfo.h"
#include "global.h"
#include "lineinfo.h"
#include "scopes.h"
#include "segments.h"
@ -56,8 +58,6 @@
void CreateDbgFile (void)
/* Create a debug info file */
{
unsigned I;
/* Open the debug info file */
FILE* F = fopen (DbgFileName, "w");
if (F == 0) {
@ -67,22 +67,20 @@ void CreateDbgFile (void)
/* Output version information */
fprintf (F, "version\tmajor=1,minor=2\n");
/* Clear the debug sym table (used to detect duplicates) */
ClearDbgSymTable ();
/* Output the segment info */
PrintDbgSegments (F);
/* Print line infos from all modules we have linked into the output file */
for (I = 0; I < CollCount (&ObjDataList); ++I) {
/* Output files */
PrintDbgFileInfo (F);
/* Get the object file */
ObjData* O = CollAtUnchecked (&ObjDataList, I);
/* Output line info */
PrintDbgLineInfo (F);
/* Output debug info */
PrintDbgInfo (O, F);
PrintDbgSyms (O, F);
}
/* Output symbols */
PrintDbgSyms (F);
/* Output scopes */
PrintDbgScopes (F);
/* Close the file */
if (fclose (F) != 0) {

View File

@ -1,111 +0,0 @@
/*****************************************************************************/
/* */
/* dbginfo.c */
/* */
/* Debug info handling for the ld65 linker */
/* */
/* */
/* */
/* (C) 2001-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. */
/* */
/*****************************************************************************/
/* common */
#include "lidefs.h"
/* ld65 */
#include "dbginfo.h"
#include "fileinfo.h"
#include "lineinfo.h"
#include "segments.h"
#include "spool.h"
/*****************************************************************************/
/* Code */
/*****************************************************************************/
void PrintDbgInfo (ObjData* O, FILE* F)
/* Print the debug info into a file */
{
unsigned I, J;
/* Output the files section */
for (I = 0; I < CollCount (&O->Files); ++I) {
FileInfo* FI = CollAt (&O->Files, I);
if (!FI->Dumped) {
fprintf (F,
"file\tid=%u,name=\"%s\",size=%lu,mtime=0x%08lX\n",
FI->Id, GetString (FI->Name), FI->Size, FI->MTime);
FI->Dumped = 1;
}
}
/* Output the line infos */
for (I = 0; I < CollCount (&O->LineInfos); ++I) {
/* Get this line info */
const LineInfo* LI = CollConstAt (&O->LineInfos, I);
/* Get the line info type and count */
unsigned Type = LI_GET_TYPE (LI->Type);
unsigned Count = LI_GET_COUNT (LI->Type);
/* Get a pointer to the spans */
const Collection* Spans = &LI->Spans;
/* Spans */
for (J = 0; J < CollCount (Spans); ++J) {
/* Get this code range */
const Span* S = CollConstAt (Spans, J);
/* Print it */
fprintf (F,
"line\tfile=%u,line=%lu,segment=%u,range=0x%lX-0x%lX",
LI->File->Id, GetSourceLine (LI), S->Seg->Id,
S->Offs, S->Offs + S->Size - 1);
/* Print type if not LI_TYPE_ASM and count if not zero */
if (Type != LI_TYPE_ASM) {
fprintf (F, ",type=%u", Type);
}
if (Count != 0) {
fprintf (F, ",count=%u", Count);
}
/* Terminate line */
fputc ('\n', F);
}
}
}

View File

@ -1,66 +0,0 @@
/*****************************************************************************/
/* */
/* dbginfo.h */
/* */
/* Debug info handling for the ld65 linker */
/* */
/* */
/* */
/* (C) 2001 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* 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. */
/* */
/*****************************************************************************/
#ifndef DBGINFO_H
#define DBGINFO_H
#include <stdio.h>
/* ld65 */
#include "objdata.h"
/*****************************************************************************/
/* Code */
/*****************************************************************************/
void PrintDbgInfo (ObjData* O, FILE* F);
/* Print the debug info into a file */
/* End of dbginfo.h */
#endif

View File

@ -67,7 +67,7 @@ static DbgSym* DbgSymPool[256];
/*****************************************************************************/
/* Code */
/* Code */
/*****************************************************************************/
@ -205,32 +205,30 @@ long GetDbgSymVal (const DbgSym* D)
void PrintDbgSyms (ObjData* O, FILE* F)
void PrintDbgSyms (FILE* F)
/* Print the debug symbols in a debug file */
{
unsigned I;
unsigned I, J;
/* Walk through all debug symbols in this module */
for (I = 0; I < CollCount (&O->DbgSyms); ++I) {
for (I = 0; I < CollCount (&ObjDataList); ++I) {
long Val;
/* Get the object file */
const ObjData* O = CollAtUnchecked (&ObjDataList, I);
/* Get the next debug symbol */
DbgSym* S = CollAt (&O->DbgSyms, I);
/* Get the symbol value */
Val = GetDbgSymVal (S);
/* Lookup this symbol in the table. If it is found in the table, it was
* already written to the file, so don't emit it twice. If it is not in
* the table, insert and output it.
*/
if (GetDbgSym (S, Val) == 0) {
/* Walk through all debug symbols in this module */
for (J = 0; J < CollCount (&O->DbgSyms); ++J) {
long Val;
SegExprDesc D;
/* Emit the base data for the entry */
fprintf (F,
/* Get the next debug symbol */
const DbgSym* S = CollConstAt (&O->DbgSyms, J);
/* Get the symbol value */
Val = GetDbgSymVal (S);
/* Emit the base data for the entry */
fprintf (F,
"sym\tname=\"%s\",value=0x%lX,addrsize=%s,type=%s",
GetString (S->Name),
Val,
@ -252,10 +250,7 @@ void PrintDbgSyms (ObjData* O, FILE* F)
/* Terminate the output line */
fputc ('\n', F);
/* Insert the symbol into the table */
InsertDbgSym (S, Val);
}
}
}
}

View File

@ -96,7 +96,7 @@ void ClearDbgSymTable (void);
* or debug labels the first time.
*/
void PrintDbgSyms (ObjData* O, FILE* F);
void PrintDbgSyms (FILE* F);
/* Print the debug symbols in a debug file */
void PrintDbgSymLabels (ObjData* O, FILE* F);

View File

@ -2,7 +2,7 @@
/* */
/* fileinfo.c */
/* */
/* sOURCE FILE INFO STRUCTURE */
/* Source file info structure */
/* */
/* */
/* */
@ -40,6 +40,8 @@
/* ld65 */
#include "fileio.h"
#include "fileinfo.h"
#include "objdata.h"
#include "spool.h"
@ -110,7 +112,7 @@ static FileInfo* NewFileInfo (void)
FileInfo* FI = xmalloc (sizeof (FileInfo));
/* Initialize stuff */
FI->Id = Id++;
FI->Id = Id++;
FI->Dumped = 0;
/* Return the new struct */
@ -180,3 +182,29 @@ FileInfo* ReadFileInfo (FILE* F, ObjData* O)
void PrintDbgFileInfo (FILE* F)
/* Output the file info to a debug info file */
{
unsigned I, J;
/* Print file infos from all modules we have linked into the output file */
for (I = 0; I < CollCount (&ObjDataList); ++I) {
/* Get the object file */
ObjData* O = CollAtUnchecked (&ObjDataList, I);
/* Output the files section */
for (J = 0; J < CollCount (&O->Files); ++J) {
FileInfo* FI = CollAt (&O->Files, J);
if (!FI->Dumped) {
fprintf (F,
"file\tid=%u,name=\"%s\",size=%lu,mtime=0x%08lX\n",
FI->Id, GetString (FI->Name), FI->Size, FI->MTime);
FI->Dumped = 1;
}
}
}
}

View File

@ -75,6 +75,9 @@ struct FileInfo {
FileInfo* ReadFileInfo (FILE* F, ObjData* O);
/* Read a file info from a file and return it */
void PrintDbgFileInfo (FILE* F);
/* Output the file info to a debug info file */
/* End of fileinfo.h */

View File

@ -204,4 +204,57 @@ void RelocLineInfo (Segment* S)
void PrintDbgLineInfo (FILE* F)
/* Output the line infos to a debug info file */
{
unsigned I, J, K;
/* Print line infos from all modules we have linked into the output file */
for (I = 0; I < CollCount (&ObjDataList); ++I) {
/* Get the object file */
const ObjData* O = CollAtUnchecked (&ObjDataList, I);
/* Output the line infos */
for (J = 0; J < CollCount (&O->LineInfos); ++J) {
/* Get this line info */
const LineInfo* LI = CollConstAt (&O->LineInfos, J);
/* Get the line info type and count */
unsigned Type = LI_GET_TYPE (LI->Type);
unsigned Count = LI_GET_COUNT (LI->Type);
/* Get a pointer to the spans */
const Collection* Spans = &LI->Spans;
/* Spans */
for (K = 0; K < CollCount (Spans); ++K) {
/* Get this code range */
const Span* S = CollConstAt (Spans, K);
/* Print it */
fprintf (F,
"line\tfile=%u,line=%lu,segment=%u,range=0x%lX-0x%lX",
LI->File->Id, GetSourceLine (LI), S->Seg->Id,
S->Offs, S->Offs + S->Size - 1);
/* Print type if not LI_TYPE_ASM and count if not zero */
if (Type != LI_TYPE_ASM) {
fprintf (F, ",type=%u", Type);
}
if (Count != 0) {
fprintf (F, ",count=%u", Count);
}
/* Terminate line */
fputc ('\n', F);
}
}
}
}

View File

@ -171,6 +171,9 @@ INLINE unsigned long GetSourceLineFromList (const Collection* LineInfos)
GetSourceLine ((const LineInfo*) CollConstAt ((LineInfos), 0))
#endif
void PrintDbgLineInfo (FILE* F);
/* Output the line infos to a debug info file */
/* End of lineinfo.h */

View File

@ -36,7 +36,6 @@ OBJS = asserts.o \
condes.o \
config.o \
dbgfile.o \
dbginfo.o \
dbgsyms.o \
error.o \
exports.o \

View File

@ -67,7 +67,6 @@ OBJS = asserts.obj \
condes.obj \
config.obj \
dbgfile.obj \
dbginfo.obj \
dbgsyms.obj \
error.obj \
exports.obj \

View File

@ -276,7 +276,7 @@ void ObjReadScopes (FILE* F, unsigned long Pos, ObjData* O)
CollGrow (&O->Scopes, ScopeCount);
for (I = 0; I < ScopeCount; ++I) {
CollAppend (&O->Scopes, ReadScope (F, O, I));
}
}
}

View File

@ -41,6 +41,7 @@
#include "fileio.h"
#include "scopes.h"
#include "span.h"
#include "spool.h"
@ -116,3 +117,45 @@ void ResolveScopes (ObjData* Obj)
void PrintDbgScopes (FILE* F)
/* Output the scopes to a debug info file */
{
unsigned I, J;
/* Print scopes from all modules we have linked into the output file */
unsigned BaseId = 0;
for (I = 0; I < CollCount (&ObjDataList); ++I) {
/* Get the object file */
ObjData* O = CollAtUnchecked (&ObjDataList, I);
/* Output the scopes for this object file */
for (J = 0; J < CollCount (&O->Scopes); ++J) {
const Scope* S = CollConstAt (&O->Scopes, J);
fprintf (F,
"scope\tid=%u,name=\"%s\",type=%u",
BaseId + S->Id,
GetString (S->Name),
S->Type);
/* Print the size if available */
if (S->Size != 0) {
fprintf (F, ",size=%lu", S->Size);
}
/* Print parent if available */
if (S->Parent.Scope) {
fprintf (F, ",parent=%u", BaseId + S->Parent.Scope->Id);
}
/* Terminate the output line */
fputc ('\n', F);
}
/* Increment scope base id */
BaseId += CollCount (&O->Scopes);
}
}