1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 08:37:46 +00:00

LibCoreDump+Crash{Daemon,Reporter}: Make backtraces thread-specific

We want to show an individual backtrace for each thread, not one
containing backtrace entries from all threads.

Fixes #4778.
This commit is contained in:
Linus Groh 2021-01-15 20:46:59 +01:00 committed by Andreas Kling
parent 057ae36e32
commit 7668e968af
6 changed files with 86 additions and 46 deletions

View file

@ -68,29 +68,27 @@ static const ELFObjectInfo* object_info_for_region(const ELF::Core::MemoryRegion
return info_ptr;
}
Backtrace::Backtrace(const Reader& coredump)
Backtrace::Backtrace(const Reader& coredump, const ELF::Core::ThreadInfo& thread_info)
: m_thread_info(move(thread_info))
{
coredump.for_each_thread_info([this, &coredump](const ELF::Core::ThreadInfo& thread_info) {
uint32_t* ebp = (uint32_t*)thread_info.regs.ebp;
uint32_t* eip = (uint32_t*)thread_info.regs.eip;
while (ebp && eip) {
add_backtrace_entry(coredump, (FlatPtr)eip);
auto next_eip = coredump.peek_memory((FlatPtr)(ebp + 1));
auto next_ebp = coredump.peek_memory((FlatPtr)(ebp));
if (!next_eip.has_value() || !next_ebp.has_value())
break;
eip = (uint32_t*)next_eip.value();
ebp = (uint32_t*)next_ebp.value();
}
return IterationDecision::Continue;
});
uint32_t* ebp = (uint32_t*)m_thread_info.regs.ebp;
uint32_t* eip = (uint32_t*)m_thread_info.regs.eip;
while (ebp && eip) {
add_entry(coredump, (FlatPtr)eip);
auto next_eip = coredump.peek_memory((FlatPtr)(ebp + 1));
auto next_ebp = coredump.peek_memory((FlatPtr)(ebp));
if (!next_eip.has_value() || !next_ebp.has_value())
break;
eip = (uint32_t*)next_eip.value();
ebp = (uint32_t*)next_ebp.value();
}
}
Backtrace::~Backtrace()
{
}
void Backtrace::add_backtrace_entry(const Reader& coredump, FlatPtr eip)
void Backtrace::add_entry(const Reader& coredump, FlatPtr eip)
{
auto* region = coredump.region_containing((FlatPtr)eip);
if (!region) {

View file

@ -29,6 +29,7 @@
#include <AK/Types.h>
#include <LibCoreDump/Reader.h>
#include <LibDebug/DebugInfo.h>
#include <LibELF/CoreDump.h>
namespace CoreDump {
@ -54,14 +55,16 @@ public:
String to_string(bool color = false) const;
};
Backtrace(const Reader&);
Backtrace(const Reader&, const ELF::Core::ThreadInfo&);
~Backtrace();
const ELF::Core::ThreadInfo thread_info() const { return m_thread_info; }
const Vector<Entry> entries() const { return m_entries; }
private:
void add_backtrace_entry(const Reader&, FlatPtr eip);
void add_entry(const Reader&, FlatPtr eip);
ELF::Core::ThreadInfo m_thread_info;
Vector<Entry> m_entries;
};

View file

@ -26,7 +26,6 @@
#include <AK/JsonObject.h>
#include <AK/JsonValue.h>
#include <LibCoreDump/Backtrace.h>
#include <LibCoreDump/Reader.h>
#include <signal_numbers.h>
#include <string.h>
@ -161,11 +160,6 @@ const ELF::Core::MemoryRegionInfo* Reader::region_containing(FlatPtr address) co
return ret;
}
const Backtrace Reader::backtrace() const
{
return Backtrace(*this);
}
int Reader::process_pid() const
{
auto process_info = this->process_info();

View file

@ -30,7 +30,6 @@
#include <AK/MappedFile.h>
#include <AK/Noncopyable.h>
#include <AK/OwnPtr.h>
#include <LibCoreDump/Forward.h>
#include <LibELF/CoreDump.h>
#include <LibELF/Image.h>
@ -63,8 +62,6 @@ public:
};
const LibraryData* library_containing(FlatPtr address) const;
const Backtrace backtrace() const;
int process_pid() const;
u8 process_termination_signal() const;
String process_executable_path() const;