ref: ff8e38fcc6fbd484bebc4f8f2f4e499a63554cf0
parent: 192f2de704c9a0ac06e809cf962e9a9159d0117f
parent: ae0b95ec6d6df17eec9e31d96ba311c322d9283e
author: Eldred Habert <[email protected]>
date: Sun Nov 3 11:41:09 EST 2019
Merge pull request #441 from ISSOtm/linker_error_stack Make linker output error stacks instead of their top level
--- a/include/asm/fstack.h
+++ b/include/asm/fstack.h
@@ -43,6 +43,7 @@
void fstk_RunMacroArg(int32_t s);
void fstk_Init(char *s);
void fstk_Dump(void);
+void fstk_DumpToStr(char *buf, size_t len);
void fstk_DumpStringExpansions(void);
void fstk_AddIncludePath(char *s);
uint32_t fstk_RunMacro(char *s);
--- a/src/asm/fstack.c
+++ b/src/asm/fstack.c
@@ -262,6 +262,38 @@
fprintf(stderr, "%s(%d)", tzCurrentFileName, nLineNo);
}
+void fstk_DumpToStr(char *buf, size_t buflen)
+{
+ const struct sContext *pLastFile = pFileStack;
+ int retcode;
+ size_t len = buflen;
+
+ while (pLastFile) {
+ retcode = snprintf(&buf[buflen - len], len, "%s(%d) -> ",
+ pLastFile->tzFileName, pLastFile->nLine);
+ if (retcode < 0)
+ fatalerror("Failed to dump file stack to string: %s",
+ strerror(errno));
+ else if (retcode >= len)
+ len = 0;
+ else
+ len -= retcode;
+ pLastFile = pLastFile->pNext;
+ }
+
+ retcode = snprintf(&buf[buflen - len], len, "%s", tzCurrentFileName);
+ if (retcode < 0)
+ fatalerror("Failed to dump file stack to string: %s",
+ strerror(errno));
+ else if (retcode >= len)
+ len = 0;
+ else
+ len -= retcode;
+
+ if (!len)
+ warning("File stack dump too long, got truncated");
+}
+
/*
* Dump the string expansion stack to stderr
*/
--- a/src/asm/output.c
+++ b/src/asm/output.c
@@ -395,7 +395,7 @@
pPatch = allocpatch();
pPatch->nType = type;
- strcpy(pPatch->tzFilename, tzCurrentFileName);
+ fstk_DumpToStr(pPatch->tzFilename, sizeof(pPatch->tzFilename));
pPatch->nLine = nLineNo;
pPatch->nOffset = nPC;