2000-05-28 13:40:48 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* */
|
2013-05-09 11:56:54 +00:00
|
|
|
/* dbgsyms.c */
|
2000-05-28 13:40:48 +00:00
|
|
|
/* */
|
2013-05-09 11:56:54 +00:00
|
|
|
/* Debug symbol handling for the ld65 linker */
|
2000-05-28 13:40:48 +00:00
|
|
|
/* */
|
|
|
|
/* */
|
|
|
|
/* */
|
2011-01-26 19:42:17 +00:00
|
|
|
/* (C) 1998-2011, Ullrich von Bassewitz */
|
2010-07-30 20:58:51 +00:00
|
|
|
/* Roemerstrasse 52 */
|
|
|
|
/* D-70794 Filderstadt */
|
|
|
|
/* EMail: uz@cc65.org */
|
2000-05-28 13:40:48 +00:00
|
|
|
/* */
|
|
|
|
/* */
|
|
|
|
/* 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 <string.h>
|
|
|
|
|
2003-08-15 10:59:22 +00:00
|
|
|
/* common */
|
2003-12-13 19:55:22 +00:00
|
|
|
#include "addrsize.h"
|
2011-08-30 11:42:26 +00:00
|
|
|
#include "attrib.h"
|
2000-08-01 15:17:43 +00:00
|
|
|
#include "check.h"
|
2011-08-30 11:42:26 +00:00
|
|
|
#include "hlldbgsym.h"
|
2000-08-01 15:17:43 +00:00
|
|
|
#include "symdefs.h"
|
|
|
|
#include "xmalloc.h"
|
2000-08-02 13:23:06 +00:00
|
|
|
|
2000-08-01 15:17:43 +00:00
|
|
|
/* ld65 */
|
2003-06-04 12:40:14 +00:00
|
|
|
#include "dbgsyms.h"
|
2000-05-28 13:40:48 +00:00
|
|
|
#include "error.h"
|
2011-08-16 13:58:59 +00:00
|
|
|
#include "exports.h"
|
2003-06-04 12:40:14 +00:00
|
|
|
#include "expr.h"
|
2000-05-28 13:40:48 +00:00
|
|
|
#include "fileio.h"
|
2003-06-04 12:40:14 +00:00
|
|
|
#include "global.h"
|
2011-01-26 19:42:17 +00:00
|
|
|
#include "lineinfo.h"
|
2000-05-28 13:40:48 +00:00
|
|
|
#include "objdata.h"
|
2003-06-04 12:40:14 +00:00
|
|
|
#include "spool.h"
|
2011-08-30 11:42:26 +00:00
|
|
|
#include "tpool.h"
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2013-05-09 11:56:54 +00:00
|
|
|
/* Data */
|
2000-05-28 13:40:48 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-08-16 13:58:59 +00:00
|
|
|
/* Definition of the debug symbol structure */
|
|
|
|
struct DbgSym {
|
|
|
|
unsigned Id; /* Id of debug symbol */
|
2013-05-09 11:56:54 +00:00
|
|
|
DbgSym* Next; /* Pool linear list link */
|
|
|
|
ObjData* Obj; /* Object file that exports the name */
|
2011-08-18 16:27:18 +00:00
|
|
|
Collection DefLines; /* Line infos for definition */
|
|
|
|
Collection RefLines; /* Line infos for references */
|
2013-05-09 11:56:54 +00:00
|
|
|
ExprNode* Expr; /* Expression (0 if not def'd) */
|
2011-08-16 13:58:59 +00:00
|
|
|
unsigned Size; /* Symbol size if any */
|
|
|
|
unsigned OwnerId; /* Id of parent/owner */
|
|
|
|
unsigned ImportId; /* Id of import if this is one */
|
2013-05-09 11:56:54 +00:00
|
|
|
unsigned Name; /* Name */
|
|
|
|
unsigned short Type; /* Type of symbol */
|
2011-08-16 13:58:59 +00:00
|
|
|
unsigned short AddrSize; /* Address size of symbol */
|
|
|
|
};
|
|
|
|
|
2011-08-30 11:42:26 +00:00
|
|
|
/* Structure used for a high level language function or symbol */
|
|
|
|
typedef struct HLLDbgSym HLLDbgSym;
|
|
|
|
struct HLLDbgSym {
|
|
|
|
unsigned Flags; /* See above */
|
|
|
|
unsigned Name; /* String id of name */
|
|
|
|
DbgSym* Sym; /* Assembler symbol */
|
|
|
|
int Offs; /* Offset if any */
|
|
|
|
unsigned Type; /* String id of type */
|
|
|
|
unsigned ScopeId; /* Parent scope */
|
|
|
|
};
|
|
|
|
|
2000-05-28 13:40:48 +00:00
|
|
|
/* We will collect all debug symbols in the following array and remove
|
2014-06-30 09:10:35 +00:00
|
|
|
** duplicates before outputing them into a label file.
|
|
|
|
*/
|
2013-05-09 11:56:54 +00:00
|
|
|
static DbgSym* DbgSymPool[256];
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2013-05-09 11:56:54 +00:00
|
|
|
/* Code */
|
2000-05-28 13:40:48 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-08-16 13:58:59 +00:00
|
|
|
static DbgSym* NewDbgSym (unsigned Id, unsigned Type, unsigned char AddrSize,
|
|
|
|
ObjData* O)
|
2000-05-28 13:40:48 +00:00
|
|
|
/* Create a new DbgSym and return it */
|
|
|
|
{
|
|
|
|
/* Allocate memory */
|
2011-08-16 13:58:59 +00:00
|
|
|
DbgSym* D = xmalloc (sizeof (DbgSym));
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
/* Initialize the fields */
|
2011-08-16 13:58:59 +00:00
|
|
|
D->Id = Id;
|
|
|
|
D->Next = 0;
|
|
|
|
D->Obj = O;
|
2011-08-18 16:27:18 +00:00
|
|
|
D->DefLines = EmptyCollection;
|
|
|
|
D->RefLines = EmptyCollection;
|
2013-05-09 11:56:54 +00:00
|
|
|
D->Expr = 0;
|
2011-08-16 13:58:59 +00:00
|
|
|
D->Size = 0;
|
|
|
|
D->OwnerId = ~0U;
|
|
|
|
D->ImportId = ~0U;
|
2013-05-09 11:56:54 +00:00
|
|
|
D->Name = 0;
|
|
|
|
D->Type = Type;
|
2011-08-16 13:58:59 +00:00
|
|
|
D->AddrSize = AddrSize;
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
/* Return the new entry */
|
|
|
|
return D;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-08-30 11:42:26 +00:00
|
|
|
static HLLDbgSym* NewHLLDbgSym (void)
|
|
|
|
/* Create a new HLLDbgSym and return it */
|
|
|
|
{
|
|
|
|
/* Allocate memory and return it */
|
|
|
|
return xmalloc (sizeof (HLLDbgSym));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2000-05-28 13:40:48 +00:00
|
|
|
static DbgSym* GetDbgSym (DbgSym* D, long Val)
|
|
|
|
/* Check if we find the same debug symbol in the table. If we find it, return
|
2014-06-30 09:10:35 +00:00
|
|
|
** a pointer to the other occurrence, if we didn't find it, return NULL.
|
|
|
|
*/
|
2000-05-28 13:40:48 +00:00
|
|
|
{
|
|
|
|
/* Create the hash. We hash over the symbol value */
|
|
|
|
unsigned Hash = ((Val >> 24) & 0xFF) ^
|
2013-05-09 11:56:54 +00:00
|
|
|
((Val >> 16) & 0xFF) ^
|
|
|
|
((Val >> 8) & 0xFF) ^
|
|
|
|
((Val >> 0) & 0xFF);
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
/* Check for this symbol */
|
2003-06-04 12:40:14 +00:00
|
|
|
DbgSym* Sym = DbgSymPool[Hash];
|
2000-05-28 13:40:48 +00:00
|
|
|
while (Sym) {
|
2013-05-09 11:56:54 +00:00
|
|
|
/* Is this symbol identical? */
|
|
|
|
if (Sym->Name == D->Name && EqualExpr (Sym->Expr, D->Expr)) {
|
|
|
|
/* Found */
|
|
|
|
return Sym;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Next symbol */
|
|
|
|
Sym = Sym->Next;
|
2000-05-28 13:40:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* This is the first symbol of it's kind */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void InsertDbgSym (DbgSym* D, long Val)
|
|
|
|
/* Insert the symbol into the hashed symbol pool */
|
|
|
|
{
|
|
|
|
/* Create the hash. We hash over the symbol value */
|
|
|
|
unsigned Hash = ((Val >> 24) & 0xFF) ^
|
2013-05-09 11:56:54 +00:00
|
|
|
((Val >> 16) & 0xFF) ^
|
|
|
|
((Val >> 8) & 0xFF) ^
|
|
|
|
((Val >> 0) & 0xFF);
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
/* Insert the symbol */
|
|
|
|
D->Next = DbgSymPool [Hash];
|
|
|
|
DbgSymPool [Hash] = D;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-08-16 13:58:59 +00:00
|
|
|
DbgSym* ReadDbgSym (FILE* F, ObjData* O, unsigned Id)
|
2000-05-28 13:40:48 +00:00
|
|
|
/* Read a debug symbol from a file, insert and return it */
|
|
|
|
{
|
2003-11-28 22:12:14 +00:00
|
|
|
/* Read the type and address size */
|
2011-06-13 18:43:50 +00:00
|
|
|
unsigned Type = ReadVar (F);
|
2003-11-28 22:12:14 +00:00
|
|
|
unsigned char AddrSize = Read8 (F);
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2000-08-02 13:23:06 +00:00
|
|
|
/* Create a new debug symbol */
|
2011-08-16 13:58:59 +00:00
|
|
|
DbgSym* D = NewDbgSym (Id, Type, AddrSize, O);
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2011-07-31 13:28:54 +00:00
|
|
|
/* Read the id of the owner scope/symbol */
|
2011-08-04 18:47:01 +00:00
|
|
|
D->OwnerId = ReadVar (F);
|
2011-07-31 13:28:54 +00:00
|
|
|
|
2000-08-02 13:23:06 +00:00
|
|
|
/* Read and assign the name */
|
2003-06-04 12:40:14 +00:00
|
|
|
D->Name = MakeGlobalStringId (O, ReadVar (F));
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
/* Read the value */
|
2010-08-17 20:47:27 +00:00
|
|
|
if (SYM_IS_EXPR (D->Type)) {
|
2013-05-09 11:56:54 +00:00
|
|
|
D->Expr = ReadExpr (F, O);
|
2000-05-28 13:40:48 +00:00
|
|
|
} else {
|
2013-05-09 11:56:54 +00:00
|
|
|
D->Expr = LiteralExpr (Read32 (F), O);
|
2000-05-28 13:40:48 +00:00
|
|
|
}
|
|
|
|
|
2011-06-13 18:43:50 +00:00
|
|
|
/* Read the size */
|
|
|
|
if (SYM_HAS_SIZE (D->Type)) {
|
|
|
|
D->Size = ReadVar (F);
|
|
|
|
}
|
|
|
|
|
2011-08-16 13:58:59 +00:00
|
|
|
/* If this is an import, the file contains its id */
|
|
|
|
if (SYM_IS_IMPORT (D->Type)) {
|
|
|
|
D->ImportId = ReadVar (F);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If its an exports, there's also the export id, but we don't remember
|
2014-06-30 09:10:35 +00:00
|
|
|
** it but use it to let the export point back to us.
|
|
|
|
*/
|
2011-08-16 13:58:59 +00:00
|
|
|
if (SYM_IS_EXPORT (D->Type)) {
|
|
|
|
/* Get the export from the export id, then set the our id */
|
|
|
|
GetObjExport (O, ReadVar (F))->DbgSymId = Id;
|
|
|
|
}
|
|
|
|
|
2011-01-26 19:42:17 +00:00
|
|
|
/* Last is the list of line infos for this symbol */
|
2011-08-18 16:27:18 +00:00
|
|
|
ReadLineInfoList (F, O, &D->DefLines);
|
|
|
|
ReadLineInfoList (F, O, &D->RefLines);
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
/* Return the new DbgSym */
|
|
|
|
return D;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-08-30 11:42:26 +00:00
|
|
|
HLLDbgSym* ReadHLLDbgSym (FILE* F, ObjData* O, unsigned Id attribute ((unused)))
|
|
|
|
/* Read a hll debug symbol from a file, insert and return it */
|
|
|
|
{
|
|
|
|
unsigned SC;
|
|
|
|
|
|
|
|
/* Create a new HLLDbgSym */
|
|
|
|
HLLDbgSym* S = NewHLLDbgSym ();
|
|
|
|
|
|
|
|
/* Read the data */
|
|
|
|
S->Flags = ReadVar (F);
|
|
|
|
SC = HLL_GET_SC (S->Flags);
|
|
|
|
S->Name = MakeGlobalStringId (O, ReadVar (F));
|
2011-08-31 20:48:40 +00:00
|
|
|
if (HLL_HAS_SYM (S->Flags)) {
|
2011-08-30 11:42:26 +00:00
|
|
|
S->Sym = GetObjDbgSym (O, ReadVar (F));
|
|
|
|
} else {
|
|
|
|
/* Auto variables aren't attached to asm symbols */
|
|
|
|
S->Sym = 0;
|
|
|
|
}
|
|
|
|
if (SC == HLL_SC_AUTO || SC == HLL_SC_REG) {
|
|
|
|
S->Offs = ReadVar (F);
|
|
|
|
} else {
|
|
|
|
S->Offs = 0;
|
|
|
|
}
|
|
|
|
S->Type = GetTypeId (GetObjString (O, ReadVar (F)));
|
|
|
|
S->ScopeId = ReadVar (F);
|
|
|
|
|
|
|
|
/* Return the (now initialized) hll debug symbol */
|
|
|
|
return S;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-08-29 20:30:57 +00:00
|
|
|
static void ClearDbgSymTable (void)
|
2003-08-15 10:59:22 +00:00
|
|
|
/* Clear the debug symbol table */
|
|
|
|
{
|
|
|
|
unsigned I;
|
|
|
|
for (I = 0; I < sizeof (DbgSymPool) / sizeof (DbgSymPool[0]); ++I) {
|
|
|
|
DbgSym* Sym = DbgSymPool[I];
|
|
|
|
DbgSymPool[I] = 0;
|
|
|
|
while (Sym) {
|
|
|
|
DbgSym* NextSym = Sym->Next;
|
|
|
|
Sym->Next = 0;
|
|
|
|
Sym = NextSym;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-08-16 13:58:59 +00:00
|
|
|
static long GetDbgSymVal (const DbgSym* D)
|
2000-05-28 13:40:48 +00:00
|
|
|
/* Get the value of this symbol */
|
|
|
|
{
|
|
|
|
CHECK (D->Expr != 0);
|
|
|
|
return GetExprVal (D->Expr);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-16 13:58:59 +00:00
|
|
|
|
2011-08-18 16:55:53 +00:00
|
|
|
static void PrintLineInfo (FILE* F, const Collection* LineInfos, const char* Format)
|
|
|
|
/* Output an attribute with line infos */
|
|
|
|
{
|
|
|
|
if (CollCount (LineInfos) > 0) {
|
|
|
|
unsigned I;
|
|
|
|
const LineInfo* LI = CollConstAt (LineInfos, 0);
|
|
|
|
fprintf (F, Format, LI->Id);
|
|
|
|
for (I = 1; I < CollCount (LineInfos); ++I) {
|
|
|
|
LI = CollConstAt (LineInfos, I);
|
|
|
|
fprintf (F, "+%u", LI->Id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-08-30 11:42:26 +00:00
|
|
|
unsigned DbgSymCount (void)
|
|
|
|
/* Return the total number of debug symbols */
|
|
|
|
{
|
|
|
|
/* Walk over all object files */
|
|
|
|
unsigned I;
|
|
|
|
unsigned Count = 0;
|
|
|
|
for (I = 0; I < CollCount (&ObjDataList); ++I) {
|
|
|
|
|
|
|
|
/* Get this object file */
|
|
|
|
const ObjData* O = CollAtUnchecked (&ObjDataList, I);
|
|
|
|
|
|
|
|
/* Count debug symbols */
|
|
|
|
Count += CollCount (&O->DbgSyms);
|
|
|
|
}
|
|
|
|
return Count;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
unsigned HLLDbgSymCount (void)
|
|
|
|
/* Return the total number of high level language debug symbols */
|
|
|
|
{
|
|
|
|
/* Walk over all object files */
|
|
|
|
unsigned I;
|
|
|
|
unsigned Count = 0;
|
|
|
|
for (I = 0; I < CollCount (&ObjDataList); ++I) {
|
|
|
|
|
|
|
|
/* Get this object file */
|
|
|
|
const ObjData* O = CollAtUnchecked (&ObjDataList, I);
|
|
|
|
|
|
|
|
/* Count debug symbols */
|
|
|
|
Count += CollCount (&O->HLLDbgSyms);
|
|
|
|
}
|
|
|
|
return Count;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-08-04 15:58:54 +00:00
|
|
|
void PrintDbgSyms (FILE* F)
|
2003-08-15 10:59:22 +00:00
|
|
|
/* Print the debug symbols in a debug file */
|
2011-08-16 11:50:27 +00:00
|
|
|
{
|
2011-08-04 15:58:54 +00:00
|
|
|
unsigned I, J;
|
2003-08-15 10:59:22 +00:00
|
|
|
|
2011-08-04 15:58:54 +00:00
|
|
|
for (I = 0; I < CollCount (&ObjDataList); ++I) {
|
2003-08-15 10:59:22 +00:00
|
|
|
|
2011-08-04 15:58:54 +00:00
|
|
|
/* Get the object file */
|
2011-08-16 13:58:59 +00:00
|
|
|
ObjData* O = CollAtUnchecked (&ObjDataList, I);
|
2003-08-15 10:59:22 +00:00
|
|
|
|
2011-08-04 15:58:54 +00:00
|
|
|
/* Walk through all debug symbols in this module */
|
|
|
|
for (J = 0; J < CollCount (&O->DbgSyms); ++J) {
|
2003-08-15 10:59:22 +00:00
|
|
|
|
2011-08-04 15:58:54 +00:00
|
|
|
/* Get the next debug symbol */
|
|
|
|
const DbgSym* S = CollConstAt (&O->DbgSyms, J);
|
2003-08-15 10:59:22 +00:00
|
|
|
|
2011-08-04 15:58:54 +00:00
|
|
|
/* Emit the base data for the entry */
|
|
|
|
fprintf (F,
|
2011-08-18 09:56:53 +00:00
|
|
|
"sym\tid=%u,name=\"%s\",addrsize=%s",
|
2011-08-05 13:09:13 +00:00
|
|
|
O->SymBaseId + J,
|
2011-06-14 19:25:50 +00:00
|
|
|
GetString (S->Name),
|
2013-04-09 21:10:57 +00:00
|
|
|
AddrSizeToStr ((unsigned char) S->AddrSize));
|
2011-06-14 19:25:50 +00:00
|
|
|
|
2011-08-16 13:58:59 +00:00
|
|
|
/* Emit the size only if we know it */
|
|
|
|
if (S->Size != 0) {
|
|
|
|
fprintf (F, ",size=%u", S->Size);
|
2011-06-14 19:25:50 +00:00
|
|
|
}
|
|
|
|
|
2011-08-04 18:47:01 +00:00
|
|
|
/* For cheap local symbols, add the owner symbol, for others,
|
2014-06-30 09:10:35 +00:00
|
|
|
** add the owner scope.
|
|
|
|
*/
|
2011-08-04 18:47:01 +00:00
|
|
|
if (SYM_IS_STD (S->Type)) {
|
2011-08-05 13:09:13 +00:00
|
|
|
fprintf (F, ",scope=%u", O->ScopeBaseId + S->OwnerId);
|
2011-08-04 18:47:01 +00:00
|
|
|
} else {
|
2011-08-05 13:09:13 +00:00
|
|
|
fprintf (F, ",parent=%u", O->SymBaseId + S->OwnerId);
|
2011-08-04 18:47:01 +00:00
|
|
|
}
|
|
|
|
|
2011-08-18 16:27:18 +00:00
|
|
|
/* Output line infos */
|
2011-08-18 16:55:53 +00:00
|
|
|
PrintLineInfo (F, &S->DefLines, ",def=%u");
|
|
|
|
PrintLineInfo (F, &S->RefLines, ",ref=%u");
|
2011-08-18 16:27:18 +00:00
|
|
|
|
2011-08-18 10:13:11 +00:00
|
|
|
/* If this is an import, output the id of the matching export.
|
2014-06-30 09:10:35 +00:00
|
|
|
** If this is not an import, output its value and - if we have
|
|
|
|
** it - the segment.
|
|
|
|
*/
|
2011-08-16 13:58:59 +00:00
|
|
|
if (SYM_IS_IMPORT (S->Type)) {
|
|
|
|
|
|
|
|
/* Get the import */
|
|
|
|
const Import* Imp = GetObjImport (O, S->ImportId);
|
|
|
|
|
|
|
|
/* Get the export from the import */
|
|
|
|
const Export* Exp = Imp->Exp;
|
|
|
|
|
2011-08-18 10:13:11 +00:00
|
|
|
/* Output the type */
|
|
|
|
fputs (",type=imp", F);
|
|
|
|
|
|
|
|
/* If this is not a linker generated symbol, and the module
|
2014-06-30 09:10:35 +00:00
|
|
|
** that contains the export has debug info, output the debug
|
|
|
|
** symbol id for the export
|
|
|
|
*/
|
2011-08-18 10:13:11 +00:00
|
|
|
if (Exp->Obj && OBJ_HAS_DBGINFO (Exp->Obj->Header.Flags)) {
|
2011-08-16 13:58:59 +00:00
|
|
|
fprintf (F, ",exp=%u", Exp->Obj->SymBaseId + Exp->DbgSymId);
|
|
|
|
}
|
2011-08-18 10:13:11 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
SegExprDesc D;
|
|
|
|
|
|
|
|
/* Get the symbol value */
|
|
|
|
long Val = GetDbgSymVal (S);
|
|
|
|
|
|
|
|
/* Output it */
|
|
|
|
fprintf (F, ",val=0x%lX", Val);
|
|
|
|
|
|
|
|
/* Check for a segmented expression and add the segment id to
|
2014-06-30 09:10:35 +00:00
|
|
|
** the debug info if we have one.
|
|
|
|
*/
|
2011-08-18 10:13:11 +00:00
|
|
|
GetSegExprVal (S->Expr, &D);
|
|
|
|
if (!D.TooComplex && D.Seg != 0) {
|
|
|
|
fprintf (F, ",seg=%u", D.Seg->Id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Output the type */
|
|
|
|
fprintf (F, ",type=%s", SYM_IS_LABEL (S->Type)? "lab" : "equ");
|
2011-08-16 13:58:59 +00:00
|
|
|
}
|
|
|
|
|
2011-06-14 19:25:50 +00:00
|
|
|
/* Terminate the output line */
|
2011-06-13 18:43:50 +00:00
|
|
|
fputc ('\n', F);
|
2011-08-04 15:58:54 +00:00
|
|
|
}
|
2003-08-15 10:59:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-08-30 11:42:26 +00:00
|
|
|
void PrintHLLDbgSyms (FILE* F)
|
|
|
|
/* Print the high level language debug symbols in a debug file */
|
|
|
|
{
|
|
|
|
unsigned I, J;
|
|
|
|
|
|
|
|
for (I = 0; I < CollCount (&ObjDataList); ++I) {
|
|
|
|
|
|
|
|
/* Get the object file */
|
|
|
|
ObjData* O = CollAtUnchecked (&ObjDataList, I);
|
|
|
|
|
|
|
|
/* Walk through all hll debug symbols in this module */
|
|
|
|
for (J = 0; J < CollCount (&O->HLLDbgSyms); ++J) {
|
|
|
|
|
|
|
|
/* Get the next debug symbol */
|
|
|
|
const HLLDbgSym* S = CollConstAt (&O->HLLDbgSyms, J);
|
|
|
|
|
|
|
|
/* Get the storage class */
|
|
|
|
unsigned SC = HLL_GET_SC (S->Flags);
|
|
|
|
|
|
|
|
/* Output the base info */
|
|
|
|
fprintf (F, "csym\tid=%u,name=\"%s\",scope=%u,type=%u,sc=",
|
|
|
|
O->HLLSymBaseId + J,
|
|
|
|
GetString (S->Name),
|
|
|
|
O->ScopeBaseId + S->ScopeId,
|
|
|
|
S->Type);
|
|
|
|
switch (SC) {
|
|
|
|
case HLL_SC_AUTO: fputs ("auto", F); break;
|
|
|
|
case HLL_SC_REG: fputs ("reg", F); break;
|
|
|
|
case HLL_SC_STATIC: fputs ("static", F); break;
|
2011-08-30 13:04:08 +00:00
|
|
|
case HLL_SC_EXTERN: fputs ("ext", F); break;
|
2011-08-30 11:42:26 +00:00
|
|
|
default:
|
|
|
|
Error ("Invalid storage class %u for hll symbol", SC);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Output the offset if it is not zero */
|
|
|
|
if (S->Offs) {
|
|
|
|
fprintf (F, ",offs=%d", S->Offs);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* For non auto symbols output the debug symbol id of the asm sym */
|
2011-08-31 20:48:40 +00:00
|
|
|
if (HLL_HAS_SYM (S->Flags)) {
|
2011-09-01 10:00:31 +00:00
|
|
|
fprintf (F, ",sym=%u", O->SymBaseId + S->Sym->Id);
|
2011-08-30 11:42:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Terminate the output line */
|
|
|
|
fputc ('\n', F);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-08-29 20:30:57 +00:00
|
|
|
void PrintDbgSymLabels (FILE* F)
|
2000-05-28 13:40:48 +00:00
|
|
|
/* Print the debug symbols in a VICE label file */
|
|
|
|
{
|
2011-08-29 20:30:57 +00:00
|
|
|
unsigned I, J;
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2011-08-29 20:30:57 +00:00
|
|
|
/* Clear the symbol table */
|
|
|
|
ClearDbgSymTable ();
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2011-08-29 20:30:57 +00:00
|
|
|
/* Create labels from all modules we have linked into the output file */
|
|
|
|
for (I = 0; I < CollCount (&ObjDataList); ++I) {
|
2003-08-15 10:59:22 +00:00
|
|
|
|
2011-08-29 20:30:57 +00:00
|
|
|
/* Get the object file */
|
|
|
|
ObjData* O = CollAtUnchecked (&ObjDataList, I);
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2011-08-29 20:30:57 +00:00
|
|
|
/* Walk through all debug symbols in this module */
|
|
|
|
for (J = 0; J < CollCount (&O->DbgSyms); ++J) {
|
2003-08-15 10:59:22 +00:00
|
|
|
|
2011-08-29 20:30:57 +00:00
|
|
|
long Val;
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2011-08-29 20:30:57 +00:00
|
|
|
/* Get the next debug symbol */
|
|
|
|
DbgSym* D = CollAt (&O->DbgSyms, J);
|
|
|
|
|
|
|
|
/* Emit this symbol only if it is a label (ignore equates and imports) */
|
|
|
|
if (SYM_IS_EQUATE (D->Type) || SYM_IS_IMPORT (D->Type)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the symbol value */
|
|
|
|
Val = GetDbgSymVal (D);
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2011-08-29 20:30:57 +00:00
|
|
|
/* Lookup this symbol in the table. If it is found in the table, it was
|
2014-06-30 09:10:35 +00:00
|
|
|
** already written to the file, so don't emit it twice. If it is not in
|
|
|
|
** the table, insert and output it.
|
|
|
|
*/
|
2011-08-29 20:30:57 +00:00
|
|
|
if (GetDbgSym (D, Val) == 0) {
|
|
|
|
|
|
|
|
/* Emit the VICE label line */
|
|
|
|
fprintf (F, "al %06lX .%s\n", Val, GetString (D->Name));
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2011-08-29 20:30:57 +00:00
|
|
|
/* Insert the symbol into the table */
|
|
|
|
InsertDbgSym (D, Val);
|
|
|
|
}
|
|
|
|
}
|
2000-05-28 13:40:48 +00:00
|
|
|
}
|
|
|
|
}
|