mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 04:27:44 +00:00
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.
This commit is contained in:
parent
6d64b13a1b
commit
da3c4e5df5
3 changed files with 18 additions and 11 deletions
|
@ -4,6 +4,7 @@
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <AK/ByteReader.h>
|
||||||
#include <AK/HashTable.h>
|
#include <AK/HashTable.h>
|
||||||
#include <AK/JsonObject.h>
|
#include <AK/JsonObject.h>
|
||||||
#include <AK/JsonValue.h>
|
#include <AK/JsonValue.h>
|
||||||
|
@ -139,8 +140,10 @@ Optional<FlatPtr> Reader::peek_memory(FlatPtr address) const
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
FlatPtr offset_in_region = address - region->region_start;
|
FlatPtr offset_in_region = address - region->region_start;
|
||||||
const char* region_data = image().program_header(region->program_header_index).raw_data();
|
auto* region_data = bit_cast<const u8*>(image().program_header(region->program_header_index).raw_data());
|
||||||
return *(const FlatPtr*)(®ion_data[offset_in_region]);
|
FlatPtr value { 0 };
|
||||||
|
ByteReader::load(region_data + offset_in_region, value);
|
||||||
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
const JsonObject Reader::process_info() const
|
const JsonObject Reader::process_info() const
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#include "CompilationUnit.h"
|
#include "CompilationUnit.h"
|
||||||
#include "DIE.h"
|
#include "DIE.h"
|
||||||
|
#include <AK/ByteReader.h>
|
||||||
|
|
||||||
namespace Debug::Dwarf {
|
namespace Debug::Dwarf {
|
||||||
|
|
||||||
|
@ -94,9 +95,11 @@ FlatPtr CompilationUnit::get_address(size_t index) const
|
||||||
auto base = address_table_base();
|
auto base = address_table_base();
|
||||||
auto debug_addr_data = dwarf_info().debug_addr_data();
|
auto debug_addr_data = dwarf_info().debug_addr_data();
|
||||||
VERIFY(base < debug_addr_data.size());
|
VERIFY(base < debug_addr_data.size());
|
||||||
auto addresses = reinterpret_cast<FlatPtr const*>(debug_addr_data.offset(base));
|
auto addresses = debug_addr_data.slice(base);
|
||||||
VERIFY(base + index * sizeof(FlatPtr) < debug_addr_data.size());
|
VERIFY(index * sizeof(FlatPtr) < addresses.size());
|
||||||
return addresses[index];
|
FlatPtr value { 0 };
|
||||||
|
ByteReader::load<FlatPtr>(addresses.offset_pointer(index * sizeof(FlatPtr)), value);
|
||||||
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
char const* CompilationUnit::get_string(size_t index) const
|
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();
|
auto debug_str_offsets_data = dwarf_info().debug_str_offsets_data();
|
||||||
VERIFY(base < debug_str_offsets_data.size());
|
VERIFY(base < debug_str_offsets_data.size());
|
||||||
// FIXME: This assumes DWARF32
|
// FIXME: This assumes DWARF32
|
||||||
auto offsets = reinterpret_cast<u32 const*>(debug_str_offsets_data.offset(base));
|
auto offsets = debug_str_offsets_data.slice(base);
|
||||||
VERIFY(base + index * sizeof(u32) < debug_str_offsets_data.size());
|
VERIFY(index * sizeof(u32) < offsets.size());
|
||||||
auto offset = offsets[index];
|
auto offset = ByteReader::load32(offsets.offset_pointer(index * sizeof(u32)));
|
||||||
return reinterpret_cast<char const*>(dwarf_info().debug_strings_data().offset(offset));
|
return bit_cast<char const*>(dwarf_info().debug_strings_data().offset(offset));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include "AttributeValue.h"
|
#include "AttributeValue.h"
|
||||||
#include "CompilationUnit.h"
|
#include "CompilationUnit.h"
|
||||||
|
|
||||||
|
#include <AK/ByteReader.h>
|
||||||
#include <AK/MemoryStream.h>
|
#include <AK/MemoryStream.h>
|
||||||
#include <LibDebug/DebugInfo.h>
|
#include <LibDebug/DebugInfo.h>
|
||||||
|
|
||||||
|
@ -344,8 +345,8 @@ void DwarfInfo::build_cached_dies() const
|
||||||
auto index = ranges->as_unsigned();
|
auto index = ranges->as_unsigned();
|
||||||
auto base = die.compilation_unit().range_lists_base();
|
auto base = die.compilation_unit().range_lists_base();
|
||||||
// FIXME: This assumes that the format is DWARf32
|
// FIXME: This assumes that the format is DWARf32
|
||||||
auto offsets = reinterpret_cast<u32 const*>(debug_range_lists_data().offset(base));
|
auto offsets = debug_range_lists_data().slice(base);
|
||||||
offset = offsets[index] + base;
|
offset = ByteReader::load32(offsets.offset_pointer(index * sizeof(u32))) + base;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector<DIERange> entries;
|
Vector<DIERange> entries;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue