1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 02:07:35 +00:00

LibDebug+LibCoredump: Replace remaining reinterpret_casts and C casts

You misused your toys and I'm now taking them away, reflect on what you
did wrong for a bit.
This commit is contained in:
Ali Mohammad Pur 2022-01-27 04:51:17 +03:30 committed by Linus Groh
parent da3c4e5df5
commit e0db9cb876
10 changed files with 68 additions and 64 deletions

View file

@ -231,7 +231,7 @@ static void parse_variable_location(Dwarf::DIE const& variable_die, DebugInfo::V
break;
}
default:
dbgln("Warning: unhandled Dwarf location type: {}", (int)location_info.value().type());
dbgln("Warning: unhandled Dwarf location type: {}", to_underlying(location_info.value().type()));
}
}
@ -429,14 +429,16 @@ Optional<Dwarf::LineProgram::DirectoryAndFile> DebugInfo::get_source_path_of_inl
{
auto caller_file = die.get_attribute(Dwarf::Attribute::CallFile);
if (caller_file.has_value()) {
u32 file_index = 0;
size_t file_index = 0;
if (caller_file->type() == Dwarf::AttributeValue::Type::UnsignedNumber) {
file_index = caller_file->as_unsigned();
} else if (caller_file->type() == Dwarf::AttributeValue::Type::SignedNumber) {
// For some reason, the file_index is sometimes stored as a signed number.
VERIFY(caller_file->as_signed() >= 0);
file_index = (u32)caller_file->as_signed();
auto signed_file_index = caller_file->as_signed();
VERIFY(signed_file_index >= 0);
VERIFY(static_cast<u64>(signed_file_index) <= NumericLimits<size_t>::max());
file_index = static_cast<size_t>(caller_file->as_signed());
} else {
return {};
}

View file

@ -80,11 +80,11 @@ OwnPtr<DebugSession> DebugSession::exec_and_attach(String const& command,
auto parts = command.split(' ');
VERIFY(!parts.is_empty());
const char** args = (const char**)calloc(parts.size() + 1, sizeof(const char*));
const char** args = bit_cast<const char**>(calloc(parts.size() + 1, sizeof(const char*)));
for (size_t i = 0; i < parts.size(); i++) {
args[i] = parts[i].characters();
}
const char** envp = (const char**)calloc(2, sizeof(const char*));
const char** envp = bit_cast<const char**>(calloc(2, sizeof(const char*)));
// This causes loader to stop on a breakpoint before jumping to the entry point of the program.
envp[0] = "_LOADER_BREAKPOINT=1";
int rc = execvpe(args[0], const_cast<char**>(args), const_cast<char**>(envp));

View file

@ -80,7 +80,7 @@ void AddressRangesV5::for_each_range(Function<void(Range)> callback)
case RangeListEntryType::EndOfList:
return;
default:
dbgln("unsupported range list entry type: 0x{:x}", (int)entry_type);
dbgln("unsupported range list entry type: 0x{:x}", entry_type);
return;
}
}

View file

@ -84,7 +84,7 @@ AttributeValue DwarfInfo::get_attribute_value(AttributeDataForm form, ssize_t im
value.m_compilation_unit = unit;
auto assign_raw_bytes_value = [&](size_t length) {
value.m_data.as_raw_bytes = { reinterpret_cast<const u8*>(debug_info_data().data() + debug_info_stream.offset()), length };
value.m_data.as_raw_bytes = { debug_info_data().offset_pointer(debug_info_stream.offset()), length };
debug_info_stream.discard_or_error(length);
VERIFY(!debug_info_stream.has_any_error());
@ -98,7 +98,7 @@ AttributeValue DwarfInfo::get_attribute_value(AttributeDataForm form, ssize_t im
value.m_type = AttributeValue::Type::String;
auto strings_data = debug_strings_data();
value.m_data.as_string = reinterpret_cast<const char*>(strings_data.data() + offset);
value.m_data.as_string = bit_cast<const char*>(strings_data.offset_pointer(offset));
break;
}
case AttributeDataForm::Data1: {
@ -199,7 +199,7 @@ AttributeValue DwarfInfo::get_attribute_value(AttributeDataForm form, ssize_t im
debug_info_stream >> str;
VERIFY(!debug_info_stream.has_any_error());
value.m_type = AttributeValue::Type::String;
value.m_data.as_string = reinterpret_cast<const char*>(str_offset + debug_info_data().data());
value.m_data.as_string = bit_cast<const char*>(debug_info_data().offset_pointer(str_offset));
break;
}
case AttributeDataForm::Block1: {
@ -241,7 +241,7 @@ AttributeValue DwarfInfo::get_attribute_value(AttributeDataForm form, ssize_t im
value.m_type = AttributeValue::Type::String;
auto strings_data = debug_line_strings_data();
value.m_data.as_string = reinterpret_cast<const char*>(strings_data.data() + offset);
value.m_data.as_string = bit_cast<const char*>(strings_data.offset_pointer(offset));
break;
}
case AttributeDataForm::ImplicitConst: {
@ -323,7 +323,7 @@ AttributeValue DwarfInfo::get_attribute_value(AttributeDataForm form, ssize_t im
break;
}
default:
dbgln("Unimplemented AttributeDataForm: {}", (u32)form);
dbgln("Unimplemented AttributeDataForm: {}", to_underlying(form));
VERIFY_NOT_REACHED();
}
return value;

View file

@ -47,7 +47,10 @@ struct [[gnu::packed]] CompilationUnitHeader {
u32 length() const { return common.length; }
u16 version() const { return common.version; }
CompilationUnitType unit_type() const { return (common.version <= 4) ? CompilationUnitType::Full : (CompilationUnitType)v5.unit_type; }
CompilationUnitType unit_type() const
{
return (common.version <= 4) ? CompilationUnitType::Full : static_cast<CompilationUnitType>(v5.unit_type);
}
u32 abbrev_offset() const { return (common.version <= 4) ? v4.abbrev_offset : v5.abbrev_offset; }
u8 address_size() const { return (common.version <= 4) ? v4.address_size : v5.address_size; }
};

View file

@ -42,13 +42,13 @@ void LineProgram::parse_path_entries(Function<void(PathEntry& entry)> callback,
Vector<PathEntryFormat> format_descriptions;
for (u8 i = 0; i < path_entry_format_count; i++) {
size_t content_type = 0;
UnderlyingType<ContentType> content_type;
m_stream.read_LEB128_unsigned(content_type);
size_t data_form = 0;
UnderlyingType<AttributeDataForm> data_form;
m_stream.read_LEB128_unsigned(data_form);
format_descriptions.empend((ContentType)content_type, (AttributeDataForm)data_form);
format_descriptions.empend(static_cast<ContentType>(content_type), static_cast<AttributeDataForm>(data_form));
}
size_t paths_count = 0;
@ -66,7 +66,7 @@ void LineProgram::parse_path_entries(Function<void(PathEntry& entry)> callback,
entry.directory_index = value.as_unsigned();
break;
default:
dbgln_if(DWARF_DEBUG, "Unhandled path list attribute: {}", (int)format_description.type);
dbgln_if(DWARF_DEBUG, "Unhandled path list attribute: {}", to_underlying(format_description.type));
}
}
callback(entry);
@ -280,7 +280,7 @@ void LineProgram::run_program()
{
reset_registers();
while ((size_t)m_stream.offset() < m_unit_offset + sizeof(u32) + m_unit_header.length()) {
while (m_stream.offset() < m_unit_offset + sizeof(u32) + m_unit_header.length()) {
u8 opcode = 0;
m_stream >> opcode;