mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-01-31 03:27:39 +00:00
Make --ftrace more crash proof with foreign code
Sometimes we need to interact with code that wasn't compiled using `-fno-omit-frame-pointer`. For example, if a function pointer gets passed and called by a foreign function, linked by cosmo_dlopen(). Function call tracing will now detect backtrace pointer corruption and simply reduce the indentation level back to zero, as a result.
This commit is contained in:
parent
38af54a2dd
commit
e9a756e78b
2 changed files with 6 additions and 1 deletions
|
@ -17,6 +17,8 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/intrin/describebacktrace.internal.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/intrin/weaken.h"
|
||||
#include "libc/log/libfatal.internal.h"
|
||||
#include "libc/nexgen32e/stackframe.h"
|
||||
|
||||
|
@ -28,6 +30,9 @@ dontinstrument const char *(DescribeBacktrace)(char buf[N],
|
|||
char *pe = p + N;
|
||||
bool gotsome = false;
|
||||
while (fr) {
|
||||
if (_weaken(kisdangerous) && _weaken(kisdangerous)(fr)) {
|
||||
break;
|
||||
}
|
||||
if (p + 16 + 1 + 1 <= pe) {
|
||||
if (gotsome) {
|
||||
*p++ = ' ';
|
||||
|
|
|
@ -51,7 +51,7 @@ static struct CosmoFtrace g_ftrace;
|
|||
|
||||
__funline int GetNestingLevelImpl(struct StackFrame *frame) {
|
||||
int nesting = -2;
|
||||
while (frame) {
|
||||
while (frame && !kisdangerous(frame)) {
|
||||
++nesting;
|
||||
frame = frame->next;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue