Implement thread->where (backtrace)

This commit is contained in:
Ivan Chikish 2023-07-20 18:18:12 +03:00
parent 5b097f62ae
commit 7a5ba3bf6a
4 changed files with 16 additions and 2 deletions

View file

@ -68,5 +68,7 @@ struct ProcessOps {
SysResult (*processNeeded)(Thread *thread);
SysResult (*registerEhFrames)(Thread *thread);
void (*where)(Thread *);
};
} // namespace orbis

View file

@ -32,6 +32,9 @@ struct Thread {
uint64_t evfResultPattern;
uint64_t evfIsCancelled;
// Print backtrace
void where();
// FIXME: implement thread destruction
void incRef() {}
void decRef() {}

View file

@ -1,5 +1,6 @@
#include "orbis/KernelContext.hpp"
#include "orbis/thread/Process.hpp"
#include "orbis/thread/ProcessOps.hpp"
#include "orbis/utils/Logs.hpp"
#include <sys/mman.h>
#include <sys/unistd.h>
@ -85,14 +86,14 @@ long KernelContext::getTscFreq() {
long timer_data[samples];
long error_data[samples];
struct timespec ts0;
struct ::timespec ts0;
clock_gettime(CLOCK_MONOTONIC, &ts0);
long sec_base = ts0.tv_sec;
for (int i = 0; i < samples; i++) {
usleep(200);
error_data[i] = (__builtin_ia32_lfence(), __builtin_ia32_rdtsc());
struct timespec ts;
struct ::timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
rdtsc_data[i] = (__builtin_ia32_lfence(), __builtin_ia32_rdtsc());
timer_data[i] = ts.tv_nsec + (ts.tv_sec - sec_base) * 1'000'000'000;
@ -190,4 +191,6 @@ void log_class_string<kstring>::format(std::string &out, const void *arg) {
out += get_object(arg);
}
} // namespace logs
void Thread::where() { tproc->ops->where(this); }
} // namespace orbis

View file

@ -1,5 +1,6 @@
#include "ops.hpp"
#include "align.hpp"
#include "backtrace.hpp"
#include "io-device.hpp"
#include "linker.hpp"
#include "orbis/module/ModuleHandle.hpp"
@ -752,6 +753,10 @@ SysResult registerEhFrames(Thread *thread) {
return {};
}
void where(Thread *thread) {
rx::printStackTrace((ucontext_t *)thread->context, thread, 2);
}
} // namespace
ProcessOps rx::procOpsTable = {
@ -794,4 +799,5 @@ ProcessOps rx::procOpsTable = {
.exit = exit,
.processNeeded = processNeeded,
.registerEhFrames = registerEhFrames,
.where = where,
};