mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 12:25:06 +00:00
Kernel: Demangle kernel C++ symbols correctly again
I broke this while implementing module linking. Also move the actual demangling work to AK, in AK::demangle(const char*)
This commit is contained in:
parent
422e5166f2
commit
f75a6b9daa
4 changed files with 27 additions and 14 deletions
21
AK/Demangle.h
Normal file
21
AK/Demangle.h
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <AK/String.h>
|
||||||
|
#include <cxxabi.h>
|
||||||
|
|
||||||
|
namespace AK {
|
||||||
|
|
||||||
|
inline String demangle(const char* name)
|
||||||
|
{
|
||||||
|
int status = 0;
|
||||||
|
auto* demangled_name = abi::__cxa_demangle(name, nullptr, nullptr, &status);
|
||||||
|
auto string = String(status == 0 ? demangled_name : name);
|
||||||
|
if (status == 0)
|
||||||
|
kfree(demangled_name);
|
||||||
|
return string;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
using AK::demangle;
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#include <AK/Demangle.h>
|
||||||
#include <AK/TemporaryChange.h>
|
#include <AK/TemporaryChange.h>
|
||||||
#include <Kernel/FileSystem/FileDescription.h>
|
#include <Kernel/FileSystem/FileDescription.h>
|
||||||
#include <Kernel/KSyms.h>
|
#include <Kernel/KSyms.h>
|
||||||
|
@ -115,11 +116,6 @@ static void load_ksyms_from_data(const ByteBuffer& buffer)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ASSERT(recognized_symbol_count <= max_recognized_symbol_count);
|
ASSERT(recognized_symbol_count <= max_recognized_symbol_count);
|
||||||
size_t bytes_needed = 0;
|
|
||||||
for (int i = 0; i < recognized_symbol_count; ++i) {
|
|
||||||
auto& symbol = recognized_symbols[i];
|
|
||||||
bytes_needed += (symbol.ksym ? strlen(symbol.ksym->name) : 0) + 8 + 16;
|
|
||||||
}
|
|
||||||
for (int i = 0; i < recognized_symbol_count; ++i) {
|
for (int i = 0; i < recognized_symbol_count; ++i) {
|
||||||
auto& symbol = recognized_symbols[i];
|
auto& symbol = recognized_symbols[i];
|
||||||
if (!symbol.address)
|
if (!symbol.address)
|
||||||
|
@ -136,7 +132,7 @@ static void load_ksyms_from_data(const ByteBuffer& buffer)
|
||||||
if (symbol.ksym->address == ksym_highest_address && offset > 4096)
|
if (symbol.ksym->address == ksym_highest_address && offset > 4096)
|
||||||
dbgprintf("%p\n", symbol.address);
|
dbgprintf("%p\n", symbol.address);
|
||||||
else
|
else
|
||||||
dbgprintf("%p %s +%u\n", symbol.address, symbol.ksym->name, offset);
|
dbgprintf("%p %s +%u\n", symbol.address, demangle(symbol.ksym->name).characters(), offset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#include <AK/Demangle.h>
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
#include <Kernel/FileSystem/FileDescription.h>
|
#include <Kernel/FileSystem/FileDescription.h>
|
||||||
#include <Kernel/Process.h>
|
#include <Kernel/Process.h>
|
||||||
|
@ -682,7 +683,7 @@ String Thread::backtrace_impl() const
|
||||||
if (symbol.ksym->address == ksym_highest_address && offset > 4096)
|
if (symbol.ksym->address == ksym_highest_address && offset > 4096)
|
||||||
builder.appendf("%p\n", symbol.address);
|
builder.appendf("%p\n", symbol.address);
|
||||||
else
|
else
|
||||||
builder.appendf("%p %s +%u\n", symbol.address, symbol.ksym->name, offset);
|
builder.appendf("%p %s +%u\n", symbol.address, demangle(symbol.ksym->name).characters(), offset);
|
||||||
}
|
}
|
||||||
return builder.to_string();
|
return builder.to_string();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include "ELFLoader.h"
|
#include "ELFLoader.h"
|
||||||
|
#include <AK/Demangle.h>
|
||||||
#include <AK/QuickSort.h>
|
#include <AK/QuickSort.h>
|
||||||
#include <AK/kstdio.h>
|
#include <AK/kstdio.h>
|
||||||
#include <cxxabi.h>
|
|
||||||
|
|
||||||
#ifdef KERNEL
|
#ifdef KERNEL
|
||||||
#include <Kernel/VM/MemoryManager.h>
|
#include <Kernel/VM/MemoryManager.h>
|
||||||
|
@ -139,12 +139,7 @@ String ELFLoader::symbolicate(u32 address) const
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
return "!!";
|
return "!!";
|
||||||
auto& symbol = sorted_symbols[i - 1];
|
auto& symbol = sorted_symbols[i - 1];
|
||||||
int status = 0;
|
return String::format("%s +%u", demangle(symbol.name).characters(), address - symbol.address);
|
||||||
auto* demangled_name = abi::__cxa_demangle(symbol.name, nullptr, nullptr, &status);
|
|
||||||
auto string = String::format("%s +%u", status == 0 ? demangled_name : symbol.name, address - symbol.address);
|
|
||||||
if (status == 0)
|
|
||||||
kfree(demangled_name);
|
|
||||||
return string;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "??";
|
return "??";
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue