mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-27 14:58:30 +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. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/intrin/describebacktrace.internal.h"
|
#include "libc/intrin/describebacktrace.internal.h"
|
||||||
|
#include "libc/intrin/kprintf.h"
|
||||||
|
#include "libc/intrin/weaken.h"
|
||||||
#include "libc/log/libfatal.internal.h"
|
#include "libc/log/libfatal.internal.h"
|
||||||
#include "libc/nexgen32e/stackframe.h"
|
#include "libc/nexgen32e/stackframe.h"
|
||||||
|
|
||||||
|
@ -28,6 +30,9 @@ dontinstrument const char *(DescribeBacktrace)(char buf[N],
|
||||||
char *pe = p + N;
|
char *pe = p + N;
|
||||||
bool gotsome = false;
|
bool gotsome = false;
|
||||||
while (fr) {
|
while (fr) {
|
||||||
|
if (_weaken(kisdangerous) && _weaken(kisdangerous)(fr)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
if (p + 16 + 1 + 1 <= pe) {
|
if (p + 16 + 1 + 1 <= pe) {
|
||||||
if (gotsome) {
|
if (gotsome) {
|
||||||
*p++ = ' ';
|
*p++ = ' ';
|
||||||
|
|
|
@ -51,7 +51,7 @@ static struct CosmoFtrace g_ftrace;
|
||||||
|
|
||||||
__funline int GetNestingLevelImpl(struct StackFrame *frame) {
|
__funline int GetNestingLevelImpl(struct StackFrame *frame) {
|
||||||
int nesting = -2;
|
int nesting = -2;
|
||||||
while (frame) {
|
while (frame && !kisdangerous(frame)) {
|
||||||
++nesting;
|
++nesting;
|
||||||
frame = frame->next;
|
frame = frame->next;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue