diff options
author | Ali Mohammad Pur <ali.mpfard@gmail.com> | 2022-01-27 04:51:17 +0330 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-01-28 22:51:27 +0000 |
commit | e0db9cb8760d0c6758364572cbb106c19e1ad727 (patch) | |
tree | e5881af6076baa2b3ae05c06999ce713f5eb9b9e /Userland/Libraries/LibDebug/Dwarf | |
parent | da3c4e5df542b550d58c3031fbdb76eb681f771f (diff) | |
download | serenity-e0db9cb8760d0c6758364572cbb106c19e1ad727.zip |
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.
Diffstat (limited to 'Userland/Libraries/LibDebug/Dwarf')
-rw-r--r-- | Userland/Libraries/LibDebug/Dwarf/AddressRanges.cpp | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibDebug/Dwarf/DwarfInfo.cpp | 10 | ||||
-rw-r--r-- | Userland/Libraries/LibDebug/Dwarf/DwarfTypes.h | 5 | ||||
-rw-r--r-- | Userland/Libraries/LibDebug/Dwarf/LineProgram.cpp | 10 |
4 files changed, 15 insertions, 12 deletions
diff --git a/Userland/Libraries/LibDebug/Dwarf/AddressRanges.cpp b/Userland/Libraries/LibDebug/Dwarf/AddressRanges.cpp index fb0abf055c..caa9a9e5dd 100644 --- a/Userland/Libraries/LibDebug/Dwarf/AddressRanges.cpp +++ b/Userland/Libraries/LibDebug/Dwarf/AddressRanges.cpp @@ -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; } } diff --git a/Userland/Libraries/LibDebug/Dwarf/DwarfInfo.cpp b/Userland/Libraries/LibDebug/Dwarf/DwarfInfo.cpp index 14cec259bd..57b3991c10 100644 --- a/Userland/Libraries/LibDebug/Dwarf/DwarfInfo.cpp +++ b/Userland/Libraries/LibDebug/Dwarf/DwarfInfo.cpp @@ -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; diff --git a/Userland/Libraries/LibDebug/Dwarf/DwarfTypes.h b/Userland/Libraries/LibDebug/Dwarf/DwarfTypes.h index aa8e2c0e08..8d10f1d215 100644 --- a/Userland/Libraries/LibDebug/Dwarf/DwarfTypes.h +++ b/Userland/Libraries/LibDebug/Dwarf/DwarfTypes.h @@ -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; } }; diff --git a/Userland/Libraries/LibDebug/Dwarf/LineProgram.cpp b/Userland/Libraries/LibDebug/Dwarf/LineProgram.cpp index d30cbac173..09d27bdf7d 100644 --- a/Userland/Libraries/LibDebug/Dwarf/LineProgram.cpp +++ b/Userland/Libraries/LibDebug/Dwarf/LineProgram.cpp @@ -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; |