mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-01-04 03:49:14 +02:00
Add test function to set stack trace function line number.
This is helpful for test macros that know the line number. The line number can now be non-zero below the top of the stack without WITH_BACKTRACE so instead ignore the line number for output when it is zero.
This commit is contained in:
parent
bd461a1899
commit
5a8758cc8a
@ -109,6 +109,13 @@ stackTraceTest(void)
|
|||||||
{
|
{
|
||||||
return stackTraceTestFlag;
|
return stackTraceTestFlag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
stackTraceTestFileLineSet(unsigned int fileLine)
|
||||||
|
{
|
||||||
|
stackTrace[stackSize - 1].fileLine = fileLine;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
@ -339,18 +346,12 @@ stackTraceToZ(char *buffer, size_t bufferSize, const char *fileName, const char
|
|||||||
StackTraceData *data = &stackTrace[stackIdx];
|
StackTraceData *data = &stackTrace[stackIdx];
|
||||||
|
|
||||||
result += stackTraceFmt(
|
result += stackTraceFmt(
|
||||||
buffer, bufferSize, result, "\n%.*s:%s"
|
buffer, bufferSize, result, "\n%.*s:%s", (int)(strlen(data->fileName) - 2), data->fileName, data->functionName);
|
||||||
|
|
||||||
#ifdef WITH_BACKTRACE
|
if (data->fileLine > 0)
|
||||||
":%u"
|
result += stackTraceFmt(buffer, bufferSize, result, ":%u", data->fileLine);
|
||||||
#endif
|
|
||||||
":(%s)", (int)(strlen(data->fileName) - 2), data->fileName, data->functionName,
|
|
||||||
|
|
||||||
#ifdef WITH_BACKTRACE
|
result += stackTraceFmt(buffer, bufferSize, result, ":(%s)", stackTraceParamIdx(stackIdx));
|
||||||
data->fileLine,
|
|
||||||
#endif
|
|
||||||
|
|
||||||
stackTraceParamIdx(stackIdx));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,6 +39,9 @@ Internal Functions
|
|||||||
void stackTraceTestStart(void);
|
void stackTraceTestStart(void);
|
||||||
void stackTraceTestStop(void);
|
void stackTraceTestStop(void);
|
||||||
bool stackTraceTest(void);
|
bool stackTraceTest(void);
|
||||||
|
|
||||||
|
// Set line number for the current function on the stack
|
||||||
|
void stackTraceTestFileLineSet(unsigned int fileLine);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
LogLevel stackTracePush(const char *fileName, const char *functionName, LogLevel functionLogLevel);
|
LogLevel stackTracePush(const char *fileName, const char *functionName, LogLevel functionLogLevel);
|
||||||
|
@ -52,6 +52,11 @@ testRun(void)
|
|||||||
|
|
||||||
stackTraceTestStart();
|
stackTraceTestStart();
|
||||||
assert(stackTraceTest());
|
assert(stackTraceTest());
|
||||||
|
|
||||||
|
stackSize++;
|
||||||
|
stackTraceTestFileLineSet(888);
|
||||||
|
assert(stackTrace[stackSize - 1].fileLine == 888);
|
||||||
|
stackSize--;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,21 +92,12 @@ testRun(void)
|
|||||||
|
|
||||||
stackTraceToZ(buffer, sizeof(buffer), "file1.c", "function2", 99);
|
stackTraceToZ(buffer, sizeof(buffer), "file1.c", "function2", 99);
|
||||||
|
|
||||||
#ifdef WITH_BACKTRACE
|
|
||||||
TEST_RESULT_Z(
|
|
||||||
buffer,
|
|
||||||
"file1:function2:99:(test build required for parameters)\n"
|
|
||||||
" ... function(s) omitted ...\n"
|
|
||||||
"file1:function1:0:(void)",
|
|
||||||
" check stack trace");
|
|
||||||
#else
|
|
||||||
TEST_RESULT_Z(
|
TEST_RESULT_Z(
|
||||||
buffer,
|
buffer,
|
||||||
"file1:function2:99:(test build required for parameters)\n"
|
"file1:function2:99:(test build required for parameters)\n"
|
||||||
" ... function(s) omitted ...\n"
|
" ... function(s) omitted ...\n"
|
||||||
"file1:function1:(void)",
|
"file1:function1:(void)",
|
||||||
" check stack trace");
|
" check stack trace");
|
||||||
#endif
|
|
||||||
|
|
||||||
assert(stackTracePush("file1.c", "function2", logLevelTrace) == logLevelTrace);
|
assert(stackTracePush("file1.c", "function2", logLevelTrace) == logLevelTrace);
|
||||||
stackTrace[stackSize - 2].fileLine = 7777;
|
stackTrace[stackSize - 2].fileLine = 7777;
|
||||||
@ -152,7 +148,6 @@ testRun(void)
|
|||||||
|
|
||||||
stackTraceToZ(buffer, sizeof(buffer), "file4.c", "function4", 99);
|
stackTraceToZ(buffer, sizeof(buffer), "file4.c", "function4", 99);
|
||||||
|
|
||||||
#ifdef WITH_BACKTRACE
|
|
||||||
TEST_RESULT_Z(
|
TEST_RESULT_Z(
|
||||||
buffer,
|
buffer,
|
||||||
"file4:function4:99:(buffer full - parameters not available)\n"
|
"file4:function4:99:(buffer full - parameters not available)\n"
|
||||||
@ -161,16 +156,6 @@ testRun(void)
|
|||||||
"file1:function2:7777:(debug log level required for parameters)\n"
|
"file1:function2:7777:(debug log level required for parameters)\n"
|
||||||
"file1:function1:7777:(void)",
|
"file1:function1:7777:(void)",
|
||||||
"stack trace");
|
"stack trace");
|
||||||
#else
|
|
||||||
TEST_RESULT_Z(
|
|
||||||
buffer,
|
|
||||||
"file4:function4:99:(buffer full - parameters not available)\n"
|
|
||||||
"file3:function3:(param1: value1, param2: value2)\n"
|
|
||||||
"file2:function2:(param1: value1)\n"
|
|
||||||
"file1:function2:(debug log level required for parameters)\n"
|
|
||||||
"file1:function1:(void)",
|
|
||||||
"stack trace");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
stackTracePop("file4.c", "function4", false);
|
stackTracePop("file4.c", "function4", false);
|
||||||
assert(stackSize == 4);
|
assert(stackSize == 4);
|
||||||
|
Loading…
Reference in New Issue
Block a user