diff options
author | Ali Mohammad Pur <ali.mpfard@gmail.com> | 2022-01-27 13:22:45 +0330 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-01-28 22:51:27 +0000 |
commit | da3c4e5df542b550d58c3031fbdb76eb681f771f (patch) | |
tree | 8ceca1cfc754e99339e537434cf32eeecaa82d58 /Userland/Libraries/LibDebug | |
parent | 6d64b13a1baa8713a28b095ab860699c55fe4e67 (diff) | |
download | serenity-da3c4e5df542b550d58c3031fbdb76eb681f771f.zip |
LibDebug+LibCoredump: Use ByteReader to do unaligned reads
The previous solution of "lol whats a UB" was not nice and tripped over
itself when it was run under UBSAN, fix this by doing explicit
byte-by-byte reads where needed.
Diffstat (limited to 'Userland/Libraries/LibDebug')
-rw-r--r-- | Userland/Libraries/LibDebug/Dwarf/CompilationUnit.cpp | 17 | ||||
-rw-r--r-- | Userland/Libraries/LibDebug/Dwarf/DwarfInfo.cpp | 5 |
2 files changed, 13 insertions, 9 deletions
diff --git a/Userland/Libraries/LibDebug/Dwarf/CompilationUnit.cpp b/Userland/Libraries/LibDebug/Dwarf/CompilationUnit.cpp index d8b0343d76..9bef566e5a 100644 --- a/Userland/Libraries/LibDebug/Dwarf/CompilationUnit.cpp +++ b/Userland/Libraries/LibDebug/Dwarf/CompilationUnit.cpp @@ -6,6 +6,7 @@ #include "CompilationUnit.h" #include "DIE.h" +#include <AK/ByteReader.h> namespace Debug::Dwarf { @@ -94,9 +95,11 @@ FlatPtr CompilationUnit::get_address(size_t index) const auto base = address_table_base(); auto debug_addr_data = dwarf_info().debug_addr_data(); VERIFY(base < debug_addr_data.size()); - auto addresses = reinterpret_cast<FlatPtr const*>(debug_addr_data.offset(base)); - VERIFY(base + index * sizeof(FlatPtr) < debug_addr_data.size()); - return addresses[index]; + auto addresses = debug_addr_data.slice(base); + VERIFY(index * sizeof(FlatPtr) < addresses.size()); + FlatPtr value { 0 }; + ByteReader::load<FlatPtr>(addresses.offset_pointer(index * sizeof(FlatPtr)), value); + return value; } char const* CompilationUnit::get_string(size_t index) const @@ -105,9 +108,9 @@ char const* CompilationUnit::get_string(size_t index) const auto debug_str_offsets_data = dwarf_info().debug_str_offsets_data(); VERIFY(base < debug_str_offsets_data.size()); // FIXME: This assumes DWARF32 - auto offsets = reinterpret_cast<u32 const*>(debug_str_offsets_data.offset(base)); - VERIFY(base + index * sizeof(u32) < debug_str_offsets_data.size()); - auto offset = offsets[index]; - return reinterpret_cast<char const*>(dwarf_info().debug_strings_data().offset(offset)); + auto offsets = debug_str_offsets_data.slice(base); + VERIFY(index * sizeof(u32) < offsets.size()); + auto offset = ByteReader::load32(offsets.offset_pointer(index * sizeof(u32))); + return bit_cast<char const*>(dwarf_info().debug_strings_data().offset(offset)); } } diff --git a/Userland/Libraries/LibDebug/Dwarf/DwarfInfo.cpp b/Userland/Libraries/LibDebug/Dwarf/DwarfInfo.cpp index da94efe54b..14cec259bd 100644 --- a/Userland/Libraries/LibDebug/Dwarf/DwarfInfo.cpp +++ b/Userland/Libraries/LibDebug/Dwarf/DwarfInfo.cpp @@ -9,6 +9,7 @@ #include "AttributeValue.h" #include "CompilationUnit.h" +#include <AK/ByteReader.h> #include <AK/MemoryStream.h> #include <LibDebug/DebugInfo.h> @@ -344,8 +345,8 @@ void DwarfInfo::build_cached_dies() const auto index = ranges->as_unsigned(); auto base = die.compilation_unit().range_lists_base(); // FIXME: This assumes that the format is DWARf32 - auto offsets = reinterpret_cast<u32 const*>(debug_range_lists_data().offset(base)); - offset = offsets[index] + base; + auto offsets = debug_range_lists_data().slice(base); + offset = ByteReader::load32(offsets.offset_pointer(index * sizeof(u32))) + base; } Vector<DIERange> entries; |