mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-01 13:49:16 +00:00
LibDebug: Don't assume compilation unit index == line program index
Instead, use the `DW_AT_stmt_list` attribute of the compilation unit entry to determine the corresponding line program.
This commit is contained in:
parent
14ae04075e
commit
116f82d21a
Notes:
sideshowbarker
2024-07-17 07:35:03 +09:00
Author: https://github.com/spholz
Commit: 116f82d21a
Pull-request: https://github.com/SerenityOS/serenity/pull/24204
Reviewed-by: https://github.com/ADKaster ✅
3 changed files with 34 additions and 21 deletions
|
@ -6,22 +6,46 @@
|
|||
|
||||
#include "CompilationUnit.h"
|
||||
#include <AK/ByteReader.h>
|
||||
#include <AK/MemoryStream.h>
|
||||
#include <LibDebug/Dwarf/DIE.h>
|
||||
#include <LibDebug/Dwarf/DwarfInfo.h>
|
||||
#include <LibDebug/Dwarf/LineProgram.h>
|
||||
|
||||
namespace Debug::Dwarf {
|
||||
|
||||
CompilationUnit::CompilationUnit(DwarfInfo const& dwarf_info, u32 offset, CompilationUnitHeader const& header, NonnullOwnPtr<LineProgram>&& line_program)
|
||||
CompilationUnit::CompilationUnit(DwarfInfo const& dwarf_info, u32 offset, CompilationUnitHeader const& header)
|
||||
: m_dwarf_info(dwarf_info)
|
||||
, m_offset(offset)
|
||||
, m_header(header)
|
||||
, m_abbreviations(dwarf_info, header.abbrev_offset())
|
||||
, m_line_program(move(line_program))
|
||||
{
|
||||
VERIFY(header.version() < 5 || header.unit_type() == CompilationUnitType::Full);
|
||||
}
|
||||
|
||||
ErrorOr<NonnullOwnPtr<CompilationUnit>> CompilationUnit::create(DwarfInfo const& dwarf_info, u32 offset, CompilationUnitHeader const& header, ReadonlyBytes debug_line_data)
|
||||
{
|
||||
auto compilation_unit = TRY(adopt_nonnull_own_or_enomem(new (nothrow) CompilationUnit(dwarf_info, offset, header)));
|
||||
TRY(compilation_unit->populate_line_program(debug_line_data));
|
||||
return compilation_unit;
|
||||
}
|
||||
|
||||
ErrorOr<void> CompilationUnit::populate_line_program(ReadonlyBytes debug_line_data)
|
||||
{
|
||||
auto die = root_die();
|
||||
|
||||
auto res = TRY(die.get_attribute(Attribute::StmtList));
|
||||
if (!res.has_value())
|
||||
return EINVAL;
|
||||
VERIFY(res->form() == AttributeDataForm::SecOffset);
|
||||
|
||||
FixedMemoryStream debug_line_stream { debug_line_data };
|
||||
TRY(debug_line_stream.seek(res->as_unsigned()));
|
||||
|
||||
m_line_program = TRY(LineProgram::create(m_dwarf_info, debug_line_stream));
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
CompilationUnit::~CompilationUnit() = default;
|
||||
|
||||
DIE CompilationUnit::root_die() const
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
#include "AbbreviationsMap.h"
|
||||
#include <AK/Noncopyable.h>
|
||||
#include <AK/NonnullOwnPtr.h>
|
||||
#include <AK/OwnPtr.h>
|
||||
#include <AK/Types.h>
|
||||
|
||||
namespace Debug::Dwarf {
|
||||
|
@ -22,7 +22,7 @@ class CompilationUnit {
|
|||
AK_MAKE_NONMOVABLE(CompilationUnit);
|
||||
|
||||
public:
|
||||
CompilationUnit(DwarfInfo const& dwarf_info, u32 offset, CompilationUnitHeader const&, NonnullOwnPtr<LineProgram>&& line_program);
|
||||
static ErrorOr<NonnullOwnPtr<CompilationUnit>> create(DwarfInfo const& dwarf_info, u32 offset, CompilationUnitHeader const&, ReadonlyBytes debug_line_data);
|
||||
~CompilationUnit();
|
||||
|
||||
u32 offset() const { return m_offset; }
|
||||
|
@ -49,11 +49,14 @@ public:
|
|||
ErrorOr<u64> range_lists_base() const;
|
||||
|
||||
private:
|
||||
CompilationUnit(DwarfInfo const& dwarf_info, u32 offset, CompilationUnitHeader const&);
|
||||
ErrorOr<void> populate_line_program(ReadonlyBytes debug_line_data);
|
||||
|
||||
DwarfInfo const& m_dwarf_info;
|
||||
u32 m_offset { 0 };
|
||||
CompilationUnitHeader m_header;
|
||||
AbbreviationsMap m_abbreviations;
|
||||
NonnullOwnPtr<LineProgram> m_line_program;
|
||||
OwnPtr<LineProgram> m_line_program;
|
||||
mutable bool m_has_cached_base_address : 1 { false };
|
||||
mutable bool m_has_cached_address_table_base : 1 { false };
|
||||
mutable bool m_has_cached_string_offsets_base : 1 { false };
|
||||
|
|
|
@ -48,7 +48,6 @@ ErrorOr<void> DwarfInfo::populate_compilation_units()
|
|||
return {};
|
||||
|
||||
FixedMemoryStream debug_info_stream { m_debug_info_data };
|
||||
FixedMemoryStream line_info_stream { m_debug_line_data };
|
||||
|
||||
while (!debug_info_stream.is_eof()) {
|
||||
auto unit_offset = TRY(debug_info_stream.tell());
|
||||
|
@ -59,23 +58,10 @@ 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 = 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.
|
||||
// As a fix, we don't create compilation units for line programs that come from resource files.
|
||||
#if defined(AK_COMPILER_CLANG)
|
||||
if (line_program->looks_like_embedded_resource()) {
|
||||
TRY(debug_info_stream.seek(unit_offset));
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
m_compilation_units.append(make<CompilationUnit>(*this, unit_offset, compilation_unit_header, move(line_program)));
|
||||
TRY(debug_info_stream.discard(length_after_header));
|
||||
}
|
||||
m_compilation_units.append(TRY(CompilationUnit::create(*this, unit_offset, compilation_unit_header, m_debug_line_data)));
|
||||
TRY(debug_info_stream.discard(length_after_header));
|
||||
}
|
||||
|
||||
VERIFY(line_info_stream.is_eof());
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue