diff options
author | Ben Wiederhake <BenWiederhake.GitHub@gmx.de> | 2023-05-12 00:23:31 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-05-13 07:54:34 +0200 |
commit | c5d3de3f7d7edaed7f45084f5a0af0d3f0049ba2 (patch) | |
tree | b9ea664e890b7817f152a39dfec187f2082fa33c /Userland/Libraries/LibDebug | |
parent | 4093952a6ef7b8aedea4bca2abe8d009356cae66 (diff) | |
download | serenity-c5d3de3f7d7edaed7f45084f5a0af0d3f0049ba2.zip |
LibDebug: Propagate errors around LineProgram
Found while playing Fixme-Roulette.
Diffstat (limited to 'Userland/Libraries/LibDebug')
-rw-r--r-- | Userland/Libraries/LibDebug/Dwarf/DwarfInfo.cpp | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibDebug/Dwarf/LineProgram.cpp | 19 | ||||
-rw-r--r-- | Userland/Libraries/LibDebug/Dwarf/LineProgram.h | 5 |
3 files changed, 18 insertions, 8 deletions
diff --git a/Userland/Libraries/LibDebug/Dwarf/DwarfInfo.cpp b/Userland/Libraries/LibDebug/Dwarf/DwarfInfo.cpp index 96bb4df27c..9f73930468 100644 --- a/Userland/Libraries/LibDebug/Dwarf/DwarfInfo.cpp +++ b/Userland/Libraries/LibDebug/Dwarf/DwarfInfo.cpp @@ -59,7 +59,7 @@ ErrorOr<void> DwarfInfo::populate_compilation_units() u32 length_after_header = compilation_unit_header.length() - (compilation_unit_header.header_size() - offsetof(CompilationUnitHeader, common.version)); - auto line_program = make<LineProgram>(*this, line_info_stream); + auto line_program = TRY(LineProgram::create(*this, line_info_stream)); // HACK: Clang generates line programs for embedded resource assembly files, but not compile units. // Meaning that for graphical applications, some line info data would be unread, triggering the assertion below. diff --git a/Userland/Libraries/LibDebug/Dwarf/LineProgram.cpp b/Userland/Libraries/LibDebug/Dwarf/LineProgram.cpp index 88f26d04df..24ae35e98a 100644 --- a/Userland/Libraries/LibDebug/Dwarf/LineProgram.cpp +++ b/Userland/Libraries/LibDebug/Dwarf/LineProgram.cpp @@ -13,15 +13,22 @@ namespace Debug::Dwarf { -LineProgram::LineProgram(DwarfInfo& dwarf_info, SeekableStream& stream) +LineProgram::LineProgram(DwarfInfo& dwarf_info, SeekableStream& stream, size_t unit_offset) : m_dwarf_info(dwarf_info) , m_stream(stream) + , m_unit_offset(unit_offset) { - m_unit_offset = m_stream.tell().release_value_but_fixme_should_propagate_errors(); - parse_unit_header().release_value_but_fixme_should_propagate_errors(); - parse_source_directories().release_value_but_fixme_should_propagate_errors(); - parse_source_files().release_value_but_fixme_should_propagate_errors(); - run_program().release_value_but_fixme_should_propagate_errors(); +} + +ErrorOr<NonnullOwnPtr<LineProgram>> LineProgram::create(DwarfInfo& dwarf_info, SeekableStream& stream) +{ + auto offset = TRY(stream.tell()); + auto program = TRY(adopt_nonnull_own_or_enomem(new (nothrow) LineProgram(dwarf_info, stream, offset))); + TRY(program->parse_unit_header()); + TRY(program->parse_source_directories()); + TRY(program->parse_source_files()); + TRY(program->run_program()); + return program; } ErrorOr<void> LineProgram::parse_unit_header() diff --git a/Userland/Libraries/LibDebug/Dwarf/LineProgram.h b/Userland/Libraries/LibDebug/Dwarf/LineProgram.h index 6d39799448..b66c78fc23 100644 --- a/Userland/Libraries/LibDebug/Dwarf/LineProgram.h +++ b/Userland/Libraries/LibDebug/Dwarf/LineProgram.h @@ -7,6 +7,7 @@ #pragma once #include <AK/DeprecatedFlyString.h> +#include <AK/NonnullOwnPtr.h> #include <AK/Vector.h> #include <LibDebug/Dwarf/DwarfTypes.h> @@ -108,7 +109,7 @@ class LineProgram { AK_MAKE_NONMOVABLE(LineProgram); public: - explicit LineProgram(DwarfInfo& dwarf_info, SeekableStream& stream); + static ErrorOr<NonnullOwnPtr<LineProgram>> create(DwarfInfo& dwarf_info, SeekableStream& stream); struct LineInfo { FlatPtr address { 0 }; @@ -133,6 +134,8 @@ public: bool looks_like_embedded_resource() const; private: + LineProgram(DwarfInfo& dwarf_info, SeekableStream& stream, size_t unit_offset); + ErrorOr<void> parse_unit_header(); ErrorOr<void> parse_source_directories(); ErrorOr<void> parse_source_files(); |