[K/N] Adjust addresses when passing to source line resolution
This commit is contained in:
@@ -157,6 +157,32 @@ static size_t snprintf_with_addr(char* buf, size_t size, size_t frame, const voi
|
|||||||
}
|
}
|
||||||
#endif // ! KONAN_NO_BACKTRACE
|
#endif // ! KONAN_NO_BACKTRACE
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This is hack for better traces.
|
||||||
|
* In some cases backtrace function returns address after call instruction, while address detection need call instruction itself.
|
||||||
|
* adjustAddressForSourceInfo function tries to fix it with some heuristics.
|
||||||
|
*
|
||||||
|
* For honest solution, we should distinguish backtrace symbols got from signal handlers frames, ordinary frames,
|
||||||
|
* and addresses got from somewhere else. But for now, we assume all addresses are ordinary backtrace frames.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if (defined(KONAN_X64) || defined(KONAN_X86)) && !defined(KONAN_WINDOWS)
|
||||||
|
KNativePtr adjustAddressForSourceInfo(KNativePtr address) {
|
||||||
|
return reinterpret_cast<KNativePtr>(reinterpret_cast<uintptr_t>(address) - 1);
|
||||||
|
}
|
||||||
|
#elif (defined(KONAN_ARM32) || defined(KONAN_ARM64)) && !defined(KONAN_WINDOWS)
|
||||||
|
KNativePtr adjustAddressForSourceInfo(KNativePtr address) {
|
||||||
|
/*
|
||||||
|
* On arm instructions are always 2-bytes aligned. But odd bit can be used to encode instruction set.
|
||||||
|
* Not sure, if this can happen in our code, but let's just clear it.
|
||||||
|
*/
|
||||||
|
return reinterpret_cast<KNativePtr>((reinterpret_cast<uintptr_t>(address) & ~1) - 1);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
KNativePtr adjustAddressForSourceInfo(KNativePtr address) { return address; }
|
||||||
|
#endif
|
||||||
|
|
||||||
KStdVector<KStdString> kotlin::GetStackTraceStrings(void* const* stackTrace, size_t stackTraceSize) noexcept {
|
KStdVector<KStdString> kotlin::GetStackTraceStrings(void* const* stackTrace, size_t stackTraceSize) noexcept {
|
||||||
#if KONAN_NO_BACKTRACE
|
#if KONAN_NO_BACKTRACE
|
||||||
KStdVector<KStdString> strings;
|
KStdVector<KStdString> strings;
|
||||||
@@ -170,6 +196,7 @@ KStdVector<KStdString> kotlin::GetStackTraceStrings(void* const* stackTrace, siz
|
|||||||
for (size_t index = 0; index < stackTraceSize; ++index) {
|
for (size_t index = 0; index < stackTraceSize; ++index) {
|
||||||
KNativePtr address = stackTrace[index];
|
KNativePtr address = stackTrace[index];
|
||||||
if (!address || reinterpret_cast<uintptr_t>(address) == 1) continue;
|
if (!address || reinterpret_cast<uintptr_t>(address) == 1) continue;
|
||||||
|
address = adjustAddressForSourceInfo(address);
|
||||||
int frames_or_overflow = getSourceInfo(address, buffer, std::size(buffer));
|
int frames_or_overflow = getSourceInfo(address, buffer, std::size(buffer));
|
||||||
int frames = std::min<int>(frames_or_overflow, std::size(buffer));
|
int frames = std::min<int>(frames_or_overflow, std::size(buffer));
|
||||||
bool isSomethingPrinted = false;
|
bool isSomethingPrinted = false;
|
||||||
|
|||||||
@@ -10,13 +10,6 @@
|
|||||||
|
|
||||||
extern "C" int Kotlin_getSourceInfo_libbacktrace(void* addr, SourceInfo *result, int result_size) {
|
extern "C" int Kotlin_getSourceInfo_libbacktrace(void* addr, SourceInfo *result, int result_size) {
|
||||||
if (result_size == 0) return 0;
|
if (result_size == 0) return 0;
|
||||||
/**
|
|
||||||
* This is hack for better traces.
|
|
||||||
* backtrace function returns address after call instruction, and address detection need call instruction itself
|
|
||||||
* For honest solution, we should distinguish backtrace symbols got from signal handlers frames, ordinary frames,
|
|
||||||
* and addresses got from somewhere else. But for now, we assume all addresses are ordinary backtrace frames.
|
|
||||||
*/
|
|
||||||
addr = reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(addr) - 1);
|
|
||||||
auto ignore_error = [](void*, const char*, int){};
|
auto ignore_error = [](void*, const char*, int){};
|
||||||
static auto state = backtrace_create_state(nullptr, 1, ignore_error, nullptr);
|
static auto state = backtrace_create_state(nullptr, 1, ignore_error, nullptr);
|
||||||
if (!state) return 0;
|
if (!state) return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user