mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 10:17:35 +00:00
LibCoreDump: CoreDumpReader => CoreDump::Reader
As mentioned in 2d39da5
the usual pattern is that LibFoo provides a Foo
namespace - LibCoreDump doesn't, so this renames CoreDumpReader to
Reader and puts it in the CoreDump namespace. :^)
This commit is contained in:
parent
1ed72cc580
commit
8ec1da2fca
5 changed files with 34 additions and 26 deletions
|
@ -31,7 +31,7 @@
|
||||||
#include <AK/ScopeGuard.h>
|
#include <AK/ScopeGuard.h>
|
||||||
#include <LibCore/DirectoryWatcher.h>
|
#include <LibCore/DirectoryWatcher.h>
|
||||||
#include <LibCore/File.h>
|
#include <LibCore/File.h>
|
||||||
#include <LibCoreDump/CoreDumpReader.h>
|
#include <LibCoreDump/Reader.h>
|
||||||
#include <LibDebug/DebugInfo.h>
|
#include <LibDebug/DebugInfo.h>
|
||||||
#include <LibELF/Image.h>
|
#include <LibELF/Image.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
@ -106,7 +106,7 @@ static const ElfObjectInfo* object_info_for_region(const ELF::Core::MemoryRegion
|
||||||
return info_ptr;
|
return info_ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static String backtrace_line(const CoreDumpReader& coredump, FlatPtr eip)
|
static String backtrace_line(const CoreDump::Reader& coredump, FlatPtr eip)
|
||||||
{
|
{
|
||||||
auto* region = coredump.region_containing((FlatPtr)eip);
|
auto* region = coredump.region_containing((FlatPtr)eip);
|
||||||
if (!region)
|
if (!region)
|
||||||
|
@ -133,7 +133,7 @@ static String backtrace_line(const CoreDumpReader& coredump, FlatPtr eip)
|
||||||
static void backtrace(const String& coredump_path)
|
static void backtrace(const String& coredump_path)
|
||||||
{
|
{
|
||||||
size_t thread_index = 0;
|
size_t thread_index = 0;
|
||||||
auto coredump = CoreDumpReader::create(coredump_path);
|
auto coredump = CoreDump::Reader::create(coredump_path);
|
||||||
coredump->for_each_thread_info([&thread_index, &coredump](const ELF::Core::ThreadInfo* thread_info) {
|
coredump->for_each_thread_info([&thread_index, &coredump](const ELF::Core::ThreadInfo* thread_info) {
|
||||||
dbgln("Backtrace for thread #{}, tid={}", thread_index++, thread_info->tid);
|
dbgln("Backtrace for thread #{}, tid={}", thread_index++, thread_info->tid);
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
#include <AK/QuickSort.h>
|
#include <AK/QuickSort.h>
|
||||||
#include <AK/RefPtr.h>
|
#include <AK/RefPtr.h>
|
||||||
#include <LibCore/File.h>
|
#include <LibCore/File.h>
|
||||||
#include <LibCoreDump/CoreDumpReader.h>
|
#include <LibCoreDump/Reader.h>
|
||||||
#include <LibELF/Image.h>
|
#include <LibELF/Image.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
@ -95,7 +95,7 @@ static String symbolicate(FlatPtr eip, const ELF::Core::MemoryRegionInfo* region
|
||||||
return String::format("[%s] %s", name.characters(), lib_data->lib_elf.symbolicate(eip - region->region_start, &offset).characters());
|
return String::format("[%s] %s", name.characters(), lib_data->lib_elf.symbolicate(eip - region->region_start, &offset).characters());
|
||||||
}
|
}
|
||||||
|
|
||||||
static String symbolicate_from_coredump(CoreDumpReader& coredump, u32 ptr, [[maybe_unused]] u32& offset)
|
static String symbolicate_from_coredump(CoreDump::Reader& coredump, u32 ptr, [[maybe_unused]] u32& offset)
|
||||||
{
|
{
|
||||||
auto* region = coredump.region_containing((FlatPtr)ptr);
|
auto* region = coredump.region_containing((FlatPtr)ptr);
|
||||||
if (!region) {
|
if (!region) {
|
||||||
|
@ -277,7 +277,7 @@ Result<NonnullOwnPtr<Profile>, String> Profile::load_from_perfcore_file(const St
|
||||||
auto& object = json.value().as_object();
|
auto& object = json.value().as_object();
|
||||||
auto executable_path = object.get("executable").to_string();
|
auto executable_path = object.get("executable").to_string();
|
||||||
|
|
||||||
auto coredump = CoreDumpReader::create(String::formatted("/tmp/profiler_coredumps/{}", object.get("pid").as_u32()));
|
auto coredump = CoreDump::Reader::create(String::formatted("/tmp/profiler_coredumps/{}", object.get("pid").as_u32()));
|
||||||
if (!coredump)
|
if (!coredump)
|
||||||
return String { "Could not open coredump" };
|
return String { "Could not open coredump" };
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
set(SOURCES
|
set(SOURCES
|
||||||
CoreDumpReader.cpp
|
Reader.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
serenity_lib(LibCoreDump coredump)
|
serenity_lib(LibCoreDump coredump)
|
||||||
|
|
|
@ -24,18 +24,20 @@
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "CoreDumpReader.h"
|
#include "Reader.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
OwnPtr<CoreDumpReader> CoreDumpReader::create(const String& path)
|
namespace CoreDump {
|
||||||
|
|
||||||
|
OwnPtr<Reader> Reader::create(const String& path)
|
||||||
{
|
{
|
||||||
auto mapped_file = make<MappedFile>(path);
|
auto mapped_file = make<MappedFile>(path);
|
||||||
if (!mapped_file->is_valid())
|
if (!mapped_file->is_valid())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
return make<CoreDumpReader>(move(mapped_file));
|
return make<Reader>(move(mapped_file));
|
||||||
}
|
}
|
||||||
|
|
||||||
CoreDumpReader::CoreDumpReader(OwnPtr<MappedFile>&& coredump_file)
|
Reader::Reader(OwnPtr<MappedFile>&& coredump_file)
|
||||||
: m_coredump_file(move(coredump_file))
|
: m_coredump_file(move(coredump_file))
|
||||||
, m_coredump_image((u8*)m_coredump_file->data(), m_coredump_file->size())
|
, m_coredump_image((u8*)m_coredump_file->data(), m_coredump_file->size())
|
||||||
{
|
{
|
||||||
|
@ -51,17 +53,17 @@ CoreDumpReader::CoreDumpReader(OwnPtr<MappedFile>&& coredump_file)
|
||||||
ASSERT(m_notes_segment_index != -1);
|
ASSERT(m_notes_segment_index != -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
CoreDumpReader::~CoreDumpReader()
|
Reader::~Reader()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
CoreDumpReader::NotesEntryIterator::NotesEntryIterator(const u8* notes_data)
|
Reader::NotesEntryIterator::NotesEntryIterator(const u8* notes_data)
|
||||||
: m_current((const ELF::Core::NotesEntry*)notes_data)
|
: m_current((const ELF::Core::NotesEntry*)notes_data)
|
||||||
, start(notes_data)
|
, start(notes_data)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
ELF::Core::NotesEntryHeader::Type CoreDumpReader::NotesEntryIterator::type() const
|
ELF::Core::NotesEntryHeader::Type Reader::NotesEntryIterator::type() const
|
||||||
{
|
{
|
||||||
ASSERT(m_current->header.type == ELF::Core::NotesEntryHeader::Type::MemoryRegionInfo
|
ASSERT(m_current->header.type == ELF::Core::NotesEntryHeader::Type::MemoryRegionInfo
|
||||||
|| m_current->header.type == ELF::Core::NotesEntryHeader::Type::ThreadInfo
|
|| m_current->header.type == ELF::Core::NotesEntryHeader::Type::ThreadInfo
|
||||||
|
@ -69,12 +71,12 @@ ELF::Core::NotesEntryHeader::Type CoreDumpReader::NotesEntryIterator::type() con
|
||||||
return m_current->header.type;
|
return m_current->header.type;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ELF::Core::NotesEntry* CoreDumpReader::NotesEntryIterator::current() const
|
const ELF::Core::NotesEntry* Reader::NotesEntryIterator::current() const
|
||||||
{
|
{
|
||||||
return m_current;
|
return m_current;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CoreDumpReader::NotesEntryIterator::next()
|
void Reader::NotesEntryIterator::next()
|
||||||
{
|
{
|
||||||
ASSERT(!at_end());
|
ASSERT(!at_end());
|
||||||
if (type() == ELF::Core::NotesEntryHeader::Type::ThreadInfo) {
|
if (type() == ELF::Core::NotesEntryHeader::Type::ThreadInfo) {
|
||||||
|
@ -89,12 +91,12 @@ void CoreDumpReader::NotesEntryIterator::next()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CoreDumpReader::NotesEntryIterator::at_end() const
|
bool Reader::NotesEntryIterator::at_end() const
|
||||||
{
|
{
|
||||||
return type() == ELF::Core::NotesEntryHeader::Type::Null;
|
return type() == ELF::Core::NotesEntryHeader::Type::Null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<uint32_t> CoreDumpReader::peek_memory(FlatPtr address) const
|
Optional<uint32_t> Reader::peek_memory(FlatPtr address) const
|
||||||
{
|
{
|
||||||
const auto* region = region_containing(address);
|
const auto* region = region_containing(address);
|
||||||
if (!region)
|
if (!region)
|
||||||
|
@ -105,7 +107,7 @@ Optional<uint32_t> CoreDumpReader::peek_memory(FlatPtr address) const
|
||||||
return *(const uint32_t*)(®ion_data[offset_in_region]);
|
return *(const uint32_t*)(®ion_data[offset_in_region]);
|
||||||
}
|
}
|
||||||
|
|
||||||
const ELF::Core::MemoryRegionInfo* CoreDumpReader::region_containing(FlatPtr address) const
|
const ELF::Core::MemoryRegionInfo* Reader::region_containing(FlatPtr address) const
|
||||||
{
|
{
|
||||||
const ELF::Core::MemoryRegionInfo* ret = nullptr;
|
const ELF::Core::MemoryRegionInfo* ret = nullptr;
|
||||||
for_each_memory_region_info([&ret, address](const ELF::Core::MemoryRegionInfo* region_info) {
|
for_each_memory_region_info([&ret, address](const ELF::Core::MemoryRegionInfo* region_info) {
|
||||||
|
@ -117,3 +119,5 @@ const ELF::Core::MemoryRegionInfo* CoreDumpReader::region_containing(FlatPtr add
|
||||||
});
|
});
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -32,14 +32,16 @@
|
||||||
#include <LibELF/CoreDump.h>
|
#include <LibELF/CoreDump.h>
|
||||||
#include <LibELF/Image.h>
|
#include <LibELF/Image.h>
|
||||||
|
|
||||||
class CoreDumpReader {
|
namespace CoreDump {
|
||||||
AK_MAKE_NONCOPYABLE(CoreDumpReader);
|
|
||||||
|
class Reader {
|
||||||
|
AK_MAKE_NONCOPYABLE(Reader);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static OwnPtr<CoreDumpReader> create(const String&);
|
static OwnPtr<Reader> create(const String&);
|
||||||
~CoreDumpReader();
|
~Reader();
|
||||||
|
|
||||||
CoreDumpReader(OwnPtr<MappedFile>&&);
|
Reader(OwnPtr<MappedFile>&&);
|
||||||
|
|
||||||
template<typename Func>
|
template<typename Func>
|
||||||
void for_each_memory_region_info(Func func) const;
|
void for_each_memory_region_info(Func func) const;
|
||||||
|
@ -74,7 +76,7 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename Func>
|
template<typename Func>
|
||||||
void CoreDumpReader::for_each_memory_region_info(Func func) const
|
void Reader::for_each_memory_region_info(Func func) const
|
||||||
{
|
{
|
||||||
for (NotesEntryIterator it((const u8*)m_coredump_image.program_header(m_notes_segment_index).raw_data()); !it.at_end(); it.next()) {
|
for (NotesEntryIterator it((const u8*)m_coredump_image.program_header(m_notes_segment_index).raw_data()); !it.at_end(); it.next()) {
|
||||||
if (it.type() != ELF::Core::NotesEntryHeader::Type::MemoryRegionInfo)
|
if (it.type() != ELF::Core::NotesEntryHeader::Type::MemoryRegionInfo)
|
||||||
|
@ -87,7 +89,7 @@ void CoreDumpReader::for_each_memory_region_info(Func func) const
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Func>
|
template<typename Func>
|
||||||
void CoreDumpReader::for_each_thread_info(Func func) const
|
void Reader::for_each_thread_info(Func func) const
|
||||||
{
|
{
|
||||||
for (NotesEntryIterator it((const u8*)m_coredump_image.program_header(m_notes_segment_index).raw_data()); !it.at_end(); it.next()) {
|
for (NotesEntryIterator it((const u8*)m_coredump_image.program_header(m_notes_segment_index).raw_data()); !it.at_end(); it.next()) {
|
||||||
if (it.type() != ELF::Core::NotesEntryHeader::Type::ThreadInfo)
|
if (it.type() != ELF::Core::NotesEntryHeader::Type::ThreadInfo)
|
||||||
|
@ -98,3 +100,5 @@ void CoreDumpReader::for_each_thread_info(Func func) const
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue