1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 22:48:11 +00:00

LibDebug: Implement support for DWARF 5 line programs

This commit is contained in:
Gunnar Beutner 2021-04-28 22:19:46 +02:00 committed by Andreas Kling
parent 6b4448b623
commit d2f0984fef
3 changed files with 181 additions and 44 deletions

View file

@ -6,27 +6,104 @@
#pragma once
#include "DwarfInfo.h"
#include <AK/FlyString.h>
#include <AK/MemoryStream.h>
#include <AK/Vector.h>
namespace Debug::Dwarf {
struct [[gnu::packed]] LineProgramUnitHeader32 {
struct [[gnu::packed]] LineProgramUnitHeader32Common {
u32 length;
u16 version;
};
struct [[gnu::packed]] LineProgramUnitHeader32V4Ext {
u32 header_length;
u8 min_instruction_length;
u8 max_instruction_length;
u8 default_is_stmt;
i8 line_base;
u8 line_range;
u8 opcode_base;
u8 std_opcode_lengths[12];
};
struct [[gnu::packed]] LineProgramUnitHeader32V5Ext {
u8 address_size;
u8 segment_selector_size;
u32 header_length;
u8 min_instruction_length;
u8 max_instruction_length;
u8 default_is_stmt;
i8 line_base;
u8 line_range;
u8 opcode_base;
};
struct [[gnu::packed]] LineProgramUnitHeader32 {
LineProgramUnitHeader32Common common;
union {
LineProgramUnitHeader32V4Ext v4;
LineProgramUnitHeader32V5Ext v5;
};
u8 std_opcode_lengths[13];
size_t header_size() const
{
return sizeof(common) + ((common.version <= 4) ? sizeof(v4) : sizeof(v5)) + (opcode_base() - 1) * sizeof(std_opcode_lengths[0]);
}
u32 length() const { return common.length; }
u16 version() const { return common.version; }
u32 header_length() const { return (common.version <= 4) ? v4.header_length : v5.header_length; }
u8 min_instruction_length() const { return (common.version <= 4) ? v4.min_instruction_length : v5.min_instruction_length; }
u8 default_is_stmt() const { return (common.version <= 4) ? v4.default_is_stmt : v5.default_is_stmt; }
i8 line_base() const { return (common.version <= 4) ? v4.line_base : v5.line_base; }
u8 line_range() const { return (common.version <= 4) ? v4.line_range : v5.line_range; }
u8 opcode_base() const { return (common.version <= 4) ? v4.opcode_base : v5.opcode_base; }
};
enum class ContentType {
Path = 1,
DirectoryIndex = 2,
Timestamp = 3,
Size = 4,
MD5 = 5,
LoUser = 0x2000,
HiUser = 0x3fff,
};
struct PathEntryFormat {
ContentType type;
AttributeDataForm form;
};
struct PathEntry {
String path;
size_t directory_index { 0 };
};
enum class PathListType {
Directories,
Filenames,
};
inline InputStream& operator>>(InputStream& stream, LineProgramUnitHeader32& header)
{
stream.read_or_error(Bytes { &header.common, sizeof(header.common) });
if (header.common.version <= 4)
stream.read_or_error(Bytes { &header.v4, sizeof(header.v4) });
else
stream.read_or_error(Bytes { &header.v5, sizeof(header.v5) });
stream.read_or_error(Bytes { &header.std_opcode_lengths, min(sizeof(header.std_opcode_lengths), (header.opcode_base() - 1) * sizeof(header.std_opcode_lengths[0])) });
return stream;
}
class LineProgram {
public:
explicit LineProgram(InputMemoryStream& stream);
explicit LineProgram(DwarfInfo& dwarf_info, InputMemoryStream& stream);
struct LineInfo {
u32 address { 0 };
@ -49,6 +126,8 @@ private:
void handle_standard_opcode(u8 opcode);
void handle_special_opcode(u8 opcode);
void parse_path_entries(Function<void(PathEntry& entry)> callback, PathListType list_type);
enum StandardOpcodes {
Copy = 1,
AdvancePc,
@ -76,9 +155,10 @@ private:
size_t directory_index { 0 };
};
static constexpr u16 DWARF_VERSION = 3;
static constexpr u8 SPECIAL_OPCODES_BASE = 13;
static constexpr u16 MIN_DWARF_VERSION = 3;
static constexpr u16 MAX_DWARF_VERSION = 5;
DwarfInfo& m_dwarf_info;
InputMemoryStream& m_stream;
size_t m_unit_offset { 0 };