Make linker output error stacks instead of their top level

This commit is contained in:
ISSOtm
2019-10-11 17:12:18 +02:00
parent e93d65d736
commit ae0b95ec6d
3 changed files with 34 additions and 1 deletions

View File

@@ -43,6 +43,7 @@ void fstk_RunInclude(char *tzFileName);
void fstk_RunMacroArg(int32_t s); void fstk_RunMacroArg(int32_t s);
void fstk_Init(char *s); void fstk_Init(char *s);
void fstk_Dump(void); void fstk_Dump(void);
void fstk_DumpToStr(char *buf, size_t len);
void fstk_DumpStringExpansions(void); void fstk_DumpStringExpansions(void);
void fstk_AddIncludePath(char *s); void fstk_AddIncludePath(char *s);
uint32_t fstk_RunMacro(char *s); uint32_t fstk_RunMacro(char *s);

View File

@@ -262,6 +262,38 @@ void fstk_Dump(void)
fprintf(stderr, "%s(%d)", tzCurrentFileName, nLineNo); 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 * Dump the string expansion stack to stderr
*/ */

View File

@@ -395,7 +395,7 @@ void createpatch(uint32_t type, struct Expression *expr)
pPatch = allocpatch(); pPatch = allocpatch();
pPatch->nType = type; pPatch->nType = type;
strcpy(pPatch->tzFilename, tzCurrentFileName); fstk_DumpToStr(pPatch->tzFilename, sizeof(pPatch->tzFilename));
pPatch->nLine = nLineNo; pPatch->nLine = nLineNo;
pPatch->nOffset = nPC; pPatch->nOffset = nPC;