mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-27 14:58:30 +00:00
Add C++ demangling to privileged runtime
Cosmo will now print C++ symbols correctly in --ftrace logs and backtraces. Doing this required reducing the memory requirement of the __demangle() function by 3x. This was accomplished using 16-bit indices and 16-bit malloc granularity. That puts a limit on the longest symbol we can successfully decode, which I think would be around 6553 characters long, given a 65536-byte buffer
This commit is contained in:
parent
dcd626edf8
commit
165c6b37e2
13 changed files with 727 additions and 284 deletions
|
@ -1136,10 +1136,7 @@ int __asan_print_trace(void *p) {
|
|||
kprintf(" (shadow not mapped?!)");
|
||||
}
|
||||
for (i = 0; i < ARRAYLEN(e->bt.p) && e->bt.p[i]; ++i) {
|
||||
kprintf("\n%*lx %s", 12, e->bt.p[i],
|
||||
_weaken(GetSymbolByAddr)
|
||||
? _weaken(GetSymbolByAddr)(e->bt.p[i])
|
||||
: "please __static_yoink(\"GetSymbolByAddr\")");
|
||||
kprintf("\n%*lx %t", 12, e->bt.p[i], e->bt.p[i]);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
4499
libc/intrin/demangle.c
Normal file
4499
libc/intrin/demangle.c
Normal file
File diff suppressed because it is too large
Load diff
|
@ -18,6 +18,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "ape/sections.internal.h"
|
||||
#include "libc/cosmo.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/divmod10.internal.h"
|
||||
|
@ -457,6 +458,7 @@ privileged static size_t kformat(char *b, size_t n, const char *fmt,
|
|||
const char *abet;
|
||||
signed char type;
|
||||
const char *s, *f;
|
||||
char cxxbuf[2048];
|
||||
struct CosmoTib *tib;
|
||||
unsigned long long x;
|
||||
unsigned i, j, m, rem, sign, hash, cols, prec;
|
||||
|
@ -804,10 +806,12 @@ privileged static size_t kformat(char *b, size_t n, const char *fmt,
|
|||
x = va_arg(va, intptr_t);
|
||||
if (_weaken(__symtab) && *_weaken(__symtab) &&
|
||||
(idx = _weaken(__get_symbol)(0, x)) != -1) {
|
||||
if (p + 1 <= e)
|
||||
*p++ = '&';
|
||||
/* if (p + 1 <= e) */
|
||||
/* *p++ = '&'; */
|
||||
s = (*_weaken(__symtab))->name_base +
|
||||
(*_weaken(__symtab))->names[idx];
|
||||
if (__is_mangled(s) && __demangle(cxxbuf, s, sizeof(cxxbuf)) != -1)
|
||||
s = cxxbuf;
|
||||
goto FormatString;
|
||||
}
|
||||
base = 4;
|
||||
|
|
|
@ -1,41 +0,0 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set et ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi │
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2021 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/intrin/weaken.h"
|
||||
#include "libc/runtime/internal.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
|
||||
/**
|
||||
* Exits process faster.
|
||||
*
|
||||
* @param exitcode is masked with 255
|
||||
* @noreturn
|
||||
*/
|
||||
wontreturn void quick_exit(int exitcode) {
|
||||
const uintptr_t *p;
|
||||
STRACE("quick_exit(%d)", exitcode);
|
||||
if (_weaken(fflush)) {
|
||||
_weaken(fflush)(0);
|
||||
}
|
||||
for (p = __fini_array_end; p > __fini_array_start;) {
|
||||
((void (*)(void))(*--p))();
|
||||
}
|
||||
_Exit(exitcode);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue