1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 05:57:45 +00:00

LibDebug: Store LibDebug objects on the heap & make them non-copyable

This fixes an issue were some LibDebug objects (for example,
Dwarf::CompilationUnit) held a reference to their parent
Dwarf::DwarfInfo object, which was constructed on the stack and later
moved to the heap.
This commit is contained in:
Itamar 2021-06-18 14:31:03 +03:00 committed by Andreas Kling
parent edd79ddd00
commit e9e4358a93
7 changed files with 19 additions and 10 deletions

View file

@ -7,6 +7,7 @@
#pragma once
#include "AbbreviationsMap.h"
#include <AK/Noncopyable.h>
#include <AK/Types.h>
namespace Debug::Dwarf {
@ -15,6 +16,9 @@ class DwarfInfo;
class DIE;
class CompilationUnit {
AK_MAKE_NONCOPYABLE(CompilationUnit);
AK_MAKE_NONMOVABLE(CompilationUnit);
public:
CompilationUnit(const DwarfInfo& dwarf_info, u32 offset, const CompilationUnitHeader&);

View file

@ -44,7 +44,7 @@ void DwarfInfo::populate_compilation_units()
VERIFY(compilation_unit_header.address_size() == sizeof(u32));
u32 length_after_header = compilation_unit_header.length() - (compilation_unit_header.header_size() - offsetof(CompilationUnitHeader, common.version));
m_compilation_units.empend(*this, unit_offset, compilation_unit_header);
m_compilation_units.append(make<CompilationUnit>(*this, unit_offset, compilation_unit_header));
stream.discard_or_error(length_after_header);
}
}

View file

@ -19,6 +19,9 @@
namespace Debug::Dwarf {
class DwarfInfo {
AK_MAKE_NONCOPYABLE(DwarfInfo);
AK_MAKE_NONMOVABLE(DwarfInfo);
public:
explicit DwarfInfo(const ELF::Image&);
@ -44,7 +47,7 @@ private:
ReadonlyBytes m_debug_strings_data;
ReadonlyBytes m_debug_line_strings_data;
Vector<Dwarf::CompilationUnit> m_compilation_units;
NonnullOwnPtrVector<Dwarf::CompilationUnit> m_compilation_units;
};
template<typename Callback>