mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-22 21:32:31 +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
67
examples/demangle.c
Normal file
67
examples/demangle.c
Normal file
|
@ -0,0 +1,67 @@
|
|||
#include <assert.h>
|
||||
#include <cxxabi.h>
|
||||
#include <errno.h>
|
||||
#include <stdckdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "libc/assert.h"
|
||||
#include "libc/calls/struct/timespec.h"
|
||||
#include "libc/cosmo.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/stdio/internal.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/time.h"
|
||||
|
||||
void nothing(void) {
|
||||
}
|
||||
|
||||
void (*barrier)(void) = nothing;
|
||||
|
||||
struct timespec now(void) {
|
||||
struct timespec ts;
|
||||
timespec_get(&ts, TIME_UTC);
|
||||
return ts;
|
||||
}
|
||||
|
||||
long long tonanos(struct timespec x) {
|
||||
return x.tv_sec * 1000000000ll + x.tv_nsec;
|
||||
}
|
||||
|
||||
struct timespec tub(struct timespec a, struct timespec b) {
|
||||
a.tv_sec -= b.tv_sec;
|
||||
if (a.tv_nsec < b.tv_nsec) {
|
||||
a.tv_nsec += 1000000000;
|
||||
a.tv_sec--;
|
||||
}
|
||||
a.tv_nsec -= b.tv_nsec;
|
||||
return a;
|
||||
}
|
||||
|
||||
#define BENCH(ITERATIONS, WORK_PER_RUN, CODE) \
|
||||
do { \
|
||||
struct timespec start = now(); \
|
||||
for (int i = 0; i < ITERATIONS; ++i) { \
|
||||
barrier(); \
|
||||
CODE; \
|
||||
} \
|
||||
long long work = WORK_PER_RUN * ITERATIONS; \
|
||||
double nanos = (tonanos(tub(now(), start)) + work - 1) / (double)work; \
|
||||
printf("%10g ns %2dx %s\n", nanos, ITERATIONS, #CODE); \
|
||||
} while (0)
|
||||
|
||||
char got[5632];
|
||||
char huge[262144];
|
||||
|
||||
__static_yoink("PrintBacktraceUsingSymbols");
|
||||
__static_yoink("GetSymbolTable");
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
ShowCrashReports();
|
||||
const char *sym =
|
||||
"_ZN12_GLOBAL__N_116tinyBLAS_Q0_AVX2ILi0E10block_q4_010block_"
|
||||
"q8_0fE4gemmILi3ELi2ELi0EEEvllll";
|
||||
__demangle(got, sym, sizeof(got));
|
||||
printf("%s\n", got);
|
||||
BENCH(1000, 1, __demangle(got, sym, sizeof(got)));
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue