From 4dc376b0ee8c4896c259e3b85ff01deb975fbfd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ni=C3=B1o=20D=C3=ADaz?= Date: Sat, 22 Jul 2017 14:17:27 +0100 Subject: [PATCH] Save location information of symbol definitions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Now, object files save the file name and line number where each global symbol is defined. Signed-off-by: Antonio Niño Díaz --- include/asm/fstack.h | 2 ++ include/asm/symbol.h | 4 +++- include/link/mylink.h | 2 ++ src/asm/fstack.c | 35 +++++++++++++++++++++++++++++++++-- src/asm/output.c | 3 +++ src/asm/symbol.c | 3 +++ src/link/object.c | 7 ++++++- 7 files changed, 52 insertions(+), 4 deletions(-) diff --git a/include/asm/fstack.h b/include/asm/fstack.h index c77dda4c..3d5b909a 100644 --- a/include/asm/fstack.h +++ b/include/asm/fstack.h @@ -41,6 +41,8 @@ extern void fstk_RunRept(ULONG count); FILE * fstk_FindFile(char *); +int fstk_GetLine(void); + extern int yywrap(void); #endif diff --git a/include/asm/symbol.h b/include/asm/symbol.h index 5c2ee729..1099730a 100644 --- a/include/asm/symbol.h +++ b/include/asm/symbol.h @@ -15,7 +15,9 @@ struct sSymbol { struct Section *pSection; ULONG ulMacroSize; char *pMacro; - SLONG(*Callback) (struct sSymbol *); + SLONG(*Callback) (struct sSymbol *); + char tzFileName[_MAX_PATH + 1]; /* File where the symbol was defined. */ + ULONG nFileLine; /* Line where the symbol was defined. */ }; #define SYMF_RELOC 0x001 /* symbol will be reloc'ed during * linking, it's absolute value is diff --git a/include/link/mylink.h b/include/link/mylink.h index 8fc9da1f..88e52549 100644 --- a/include/link/mylink.h +++ b/include/link/mylink.h @@ -89,6 +89,8 @@ struct sSymbol { SLONG nSectionID; /* internal to object.c */ struct sSection *pSection; SLONG nOffset; + char *pzFileName; /* Source file where the symbol was defined. */ + ULONG nFileLine; /* Line where the symbol was defined. */ }; enum ePatchType { diff --git a/src/asm/fstack.c b/src/asm/fstack.c index c15c0eb1..7b4edede 100644 --- a/src/asm/fstack.c +++ b/src/asm/fstack.c @@ -42,8 +42,8 @@ extern FILE *dependfile; /* * defines for nCurrentStatus */ -#define STAT_isInclude 0 -#define STAT_isMacro 1 +#define STAT_isInclude 0 /* 'Normal' state as well */ +#define STAT_isMacro 1 #define STAT_isMacroArg 2 #define STAT_isREPTBlock 3 @@ -151,6 +151,37 @@ popcontext(void) return (1); } +int +fstk_GetLine(void) +{ + struct sContext *pLastFile, **ppLastFile; + + switch (nCurrentStatus) { + case STAT_isInclude: + /* This is the normal mode, also used when including a file. */ + return nLineNo; + case STAT_isMacro: + break; /* Peek top file of the stack */ + case STAT_isMacroArg: + return nLineNo; /* ??? */ + case STAT_isREPTBlock: + break; /* Peek top file of the stack */ + } + + if ((pLastFile = pFileStack) != NULL) { + ppLastFile = &pFileStack; + while (pLastFile->pNext) { + ppLastFile = &(pLastFile->pNext); + pLastFile = *ppLastFile; + } + return pLastFile->nLine; + } + + /* This is only reached if the lexer is in REPT or MACRO mode but there + * are no saved contexts with the origin of said REPT or MACRO. */ + fatalerror("fstk_GetLine: Internal error."); +} + int yywrap(void) { diff --git a/src/asm/output.c b/src/asm/output.c index 34501f78..99044900 100644 --- a/src/asm/output.c +++ b/src/asm/output.c @@ -282,6 +282,9 @@ writesymbol(struct sSymbol * pSym, FILE * f) fputc(type, f); if (type != SYM_IMPORT) { + fputstring(pSym->tzFileName, f); + fputlong(pSym->nFileLine, f); + fputlong(sectid, f); fputlong(offset, f); } diff --git a/src/asm/symbol.c b/src/asm/symbol.c index 23d59b38..2a90aafe 100644 --- a/src/asm/symbol.c +++ b/src/asm/symbol.c @@ -8,6 +8,7 @@ #include #include "asm/asm.h" +#include "asm/fstack.h" #include "asm/symbol.h" #include "asm/main.h" #include "asm/mymath.h" @@ -109,6 +110,8 @@ createsymbol(char *s) (*ppsym)->pMacro = NULL; (*ppsym)->pSection = NULL; (*ppsym)->Callback = NULL; + strcpy((*ppsym)->tzFileName, tzCurrentFileName); + (*ppsym)->nFileLine = fstk_GetLine(); return (*ppsym); } else { fatalerror("No memory for symbol"); diff --git a/src/link/object.c b/src/link/object.c index 9da981ac..1f6a2334 100644 --- a/src/link/object.c +++ b/src/link/object.c @@ -126,7 +126,12 @@ obj_ReadSymbol(FILE * f) } readasciiz(&pSym->pzName, f); - if ((pSym->Type = (enum eSymbolType) fgetc(f)) != SYM_IMPORT) { + pSym->Type = (enum eSymbolType)fgetc(f); + + if (pSym->Type != SYM_IMPORT) { + readasciiz(&pSym->pzFileName, f); + pSym->nFileLine = readlong(f); + pSym->nSectionID = readlong(f); pSym->nOffset = readlong(f); }