ref: 4dc376b0ee8c4896c259e3b85ff01deb975fbfd6
parent: 3dec5698dbfc2ccab17df905c603bfc889e72c40
author: Antonio Niño Díaz <[email protected]>
date: Sat Jul 22 10:17:27 EDT 2017
Save location information of symbol definitions Now, object files save the file name and line number where each global symbol is defined. Signed-off-by: Antonio Niño Díaz <[email protected]>
--- a/include/asm/fstack.h
+++ b/include/asm/fstack.h
@@ -41,6 +41,8 @@
FILE *
fstk_FindFile(char *);
+int fstk_GetLine(void);
+
extern int yywrap(void);
#endif
--- a/include/asm/symbol.h
+++ b/include/asm/symbol.h
@@ -15,7 +15,9 @@
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
--- a/include/link/mylink.h
+++ b/include/link/mylink.h
@@ -89,6 +89,8 @@
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 {
--- a/src/asm/fstack.c
+++ b/src/asm/fstack.c
@@ -42,8 +42,8 @@
/*
* 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
@@ -149,6 +149,37 @@
return (0);
} else
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
--- a/src/asm/output.c
+++ b/src/asm/output.c
@@ -282,6 +282,9 @@
fputc(type, f);
if (type != SYM_IMPORT) {
+ fputstring(pSym->tzFileName, f);
+ fputlong(pSym->nFileLine, f);
+
fputlong(sectid, f);
fputlong(offset, f);
}
--- a/src/asm/symbol.c
+++ b/src/asm/symbol.c
@@ -8,6 +8,7 @@
#include <time.h>
#include "asm/asm.h"
+#include "asm/fstack.h"
#include "asm/symbol.h"
#include "asm/main.h"
#include "asm/mymath.h"
@@ -109,6 +110,8 @@
(*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");
--- a/src/link/object.c
+++ b/src/link/object.c
@@ -126,7 +126,12 @@
}
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);
}