From 36e36507d50fd9d36670a855eaeb8f2a58a35131 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Thu, 22 Jul 2021 01:30:24 +0200 Subject: [PATCH] Everywhere: Prefer using {:#x} over 0x{:x} We have a dedicated format specifier which adds the "0x" prefix, so let's use that instead of adding it manually. --- Kernel/Bus/PCI/Access.cpp | 6 +++--- Kernel/Graphics/VirtIOGPU/GPU.cpp | 2 +- Kernel/KSyms.cpp | 2 +- Kernel/Storage/AHCIController.cpp | 4 ++-- Kernel/Storage/AHCIPort.cpp | 8 ++++---- Kernel/Storage/IDEChannel.cpp | 2 +- Kernel/Thread.cpp | 6 +++--- Kernel/VM/MemoryManager.cpp | 6 +++--- Userland/DevTools/UserspaceEmulator/Emulator_syscalls.cpp | 2 +- Userland/Libraries/LibRegex/RegexByteCode.h | 2 +- Userland/Libraries/LibWasm/Parser/Parser.cpp | 2 +- Userland/Utilities/functrace.cpp | 4 ++-- 12 files changed, 23 insertions(+), 23 deletions(-) diff --git a/Kernel/Bus/PCI/Access.cpp b/Kernel/Bus/PCI/Access.cpp index 33f1ebf54c..1e5a7bd3f0 100644 --- a/Kernel/Bus/PCI/Access.cpp +++ b/Kernel/Bus/PCI/Access.cpp @@ -442,13 +442,13 @@ OwnPtr PCIDeviceAttributeSysFSComponent::try_to_generate_buffer() const String value; switch (m_field_bytes_width) { case 1: - value = String::formatted("0x{:x}", PCI::read8(m_device->address(), m_offset)); + value = String::formatted("{:#x}", PCI::read8(m_device->address(), m_offset)); break; case 2: - value = String::formatted("0x{:x}", PCI::read16(m_device->address(), m_offset)); + value = String::formatted("{:#x}", PCI::read16(m_device->address(), m_offset)); break; case 4: - value = String::formatted("0x{:x}", PCI::read32(m_device->address(), m_offset)); + value = String::formatted("{:#x}", PCI::read32(m_device->address(), m_offset)); break; default: VERIFY_NOT_REACHED(); diff --git a/Kernel/Graphics/VirtIOGPU/GPU.cpp b/Kernel/Graphics/VirtIOGPU/GPU.cpp index 38a418ce27..15eb5bdafc 100644 --- a/Kernel/Graphics/VirtIOGPU/GPU.cpp +++ b/Kernel/Graphics/VirtIOGPU/GPU.cpp @@ -69,7 +69,7 @@ bool GPU::handle_device_config_change() clear_pending_events(VIRTIO_GPU_EVENT_DISPLAY); } if (events & ~VIRTIO_GPU_EVENT_DISPLAY) { - dbgln("GPU: Got unknown device config change event: 0x{:x}", events); + dbgln("GPU: Got unknown device config change event: {:#x}", events); return false; } return true; diff --git a/Kernel/KSyms.cpp b/Kernel/KSyms.cpp index 499077c200..2e309aa3b4 100644 --- a/Kernel/KSyms.cpp +++ b/Kernel/KSyms.cpp @@ -151,7 +151,7 @@ NEVER_INLINE static void dump_backtrace_impl(FlatPtr base_pointer, bool use_ksym if (symbol.symbol->address == g_highest_kernel_symbol_address && offset > 4096) dbgln("{:p}", symbol.address); else - dbgln("{:p} {} +0x{:x}", symbol.address, symbol.symbol->name, offset); + dbgln("{:p} {} +{:#x}", symbol.address, symbol.symbol->name, offset); } } diff --git a/Kernel/Storage/AHCIController.cpp b/Kernel/Storage/AHCIController.cpp index fcc982dc15..a89e725ac5 100644 --- a/Kernel/Storage/AHCIController.cpp +++ b/Kernel/Storage/AHCIController.cpp @@ -92,7 +92,7 @@ AHCI::HBADefinedCapabilities AHCIController::capabilities() const u32 capabilities = hba().control_regs.cap; u32 extended_capabilities = hba().control_regs.cap2; - dbgln_if(AHCI_DEBUG, "{}: AHCI Controller Capabilities = 0x{:08x}, Extended Capabilities = 0x{:08x}", pci_address(), capabilities, extended_capabilities); + dbgln_if(AHCI_DEBUG, "{}: AHCI Controller Capabilities = {:#08x}, Extended Capabilities = {:#08x}", pci_address(), capabilities, extended_capabilities); return (AHCI::HBADefinedCapabilities) { (capabilities & 0b11111) + 1, @@ -144,7 +144,7 @@ void AHCIController::initialize() dbgln("{}: AHCI command list entries count - {}", pci_address(), hba_capabilities().max_command_list_entries_count); u32 version = hba().control_regs.version; - dbgln_if(AHCI_DEBUG, "{}: AHCI Controller Version = 0x{:08x}", pci_address(), version); + dbgln_if(AHCI_DEBUG, "{}: AHCI Controller Version = {:#08x}", pci_address(), version); hba().control_regs.ghc = 0x80000000; // Ensure that HBA knows we are AHCI aware. PCI::enable_interrupt_line(pci_address()); diff --git a/Kernel/Storage/AHCIPort.cpp b/Kernel/Storage/AHCIPort.cpp index a1c3d1d22a..b85dd8112f 100644 --- a/Kernel/Storage/AHCIPort.cpp +++ b/Kernel/Storage/AHCIPort.cpp @@ -196,7 +196,7 @@ void AHCIPort::eject() while (1) { if (m_port_registers.serr != 0) { - dbgln_if(AHCI_DEBUG, "AHCI Port {}: Eject Drive failed, SError 0x{:08x}", representative_port_index(), (u32)m_port_registers.serr); + dbgln_if(AHCI_DEBUG, "AHCI Port {}: Eject Drive failed, SError {:#08x}", representative_port_index(), (u32)m_port_registers.serr); try_disambiguate_sata_error(); VERIFY_NOT_REACHED(); } @@ -241,7 +241,7 @@ bool AHCIPort::initialize_without_reset() bool AHCIPort::initialize(ScopedSpinLock>& main_lock) { VERIFY(m_lock.is_locked()); - dbgln_if(AHCI_DEBUG, "AHCI Port {}: Initialization. Signature = 0x{:08x}", representative_port_index(), static_cast(m_port_registers.sig)); + dbgln_if(AHCI_DEBUG, "AHCI Port {}: Initialization. Signature = {:#08x}", representative_port_index(), static_cast(m_port_registers.sig)); if (!is_phy_enabled()) { // Note: If PHY is not enabled, just clear the interrupt status and enable interrupts, in case // we are going to hotplug a device later. @@ -524,7 +524,7 @@ bool AHCIPort::access_device(AsyncBlockDeviceRequest::RequestType direction, u64 // handshake error bit in PxSERR register if CFL is incorrect. command_list_entries[unused_command_header.value()].attributes = (size_t)FIS::DwordCount::RegisterHostToDevice | AHCI::CommandHeaderAttributes::P | (is_atapi_attached() ? AHCI::CommandHeaderAttributes::A : 0) | (direction == AsyncBlockDeviceRequest::RequestType::Write ? AHCI::CommandHeaderAttributes::W : 0); - dbgln_if(AHCI_DEBUG, "AHCI Port {}: CLE: ctba=0x{:08x}, ctbau=0x{:08x}, prdbc=0x{:08x}, prdtl=0x{:04x}, attributes=0x{:04x}", representative_port_index(), (u32)command_list_entries[unused_command_header.value()].ctba, (u32)command_list_entries[unused_command_header.value()].ctbau, (u32)command_list_entries[unused_command_header.value()].prdbc, (u16)command_list_entries[unused_command_header.value()].prdtl, (u16)command_list_entries[unused_command_header.value()].attributes); + dbgln_if(AHCI_DEBUG, "AHCI Port {}: CLE: ctba={:#08x}, ctbau={:#08x}, prdbc={:#08x}, prdtl={:#04x}, attributes={:#04x}", representative_port_index(), (u32)command_list_entries[unused_command_header.value()].ctba, (u32)command_list_entries[unused_command_header.value()].ctbau, (u32)command_list_entries[unused_command_header.value()].prdbc, (u16)command_list_entries[unused_command_header.value()].prdtl, (u16)command_list_entries[unused_command_header.value()].attributes); auto command_table_region = MM.allocate_kernel_region(m_command_table_pages[unused_command_header.value()].paddr().page_base(), page_round_up(sizeof(AHCI::CommandTable)), "AHCI Command Table", Region::Access::Read | Region::Access::Write, Region::Cacheable::No); auto& command_table = *(volatile AHCI::CommandTable*)command_table_region->vaddr().as_ptr(); @@ -638,7 +638,7 @@ bool AHCIPort::identify_device(ScopedSpinLock>& main_lock) while (1) { if (m_port_registers.serr != 0) { - dbgln("AHCI Port {}: Identify failed, SError 0x{:08x}", representative_port_index(), (u32)m_port_registers.serr); + dbgln("AHCI Port {}: Identify failed, SError {:#08x}", representative_port_index(), (u32)m_port_registers.serr); try_disambiguate_sata_error(); return false; } diff --git a/Kernel/Storage/IDEChannel.cpp b/Kernel/Storage/IDEChannel.cpp index f437180878..10d7f777ea 100644 --- a/Kernel/Storage/IDEChannel.cpp +++ b/Kernel/Storage/IDEChannel.cpp @@ -408,7 +408,7 @@ UNMAP_AFTER_INIT void IDEChannel::detect_disks() if (identify_block.commands_and_feature_sets_supported[1] & (1 << 10)) max_addressable_block = identify_block.user_addressable_logical_sectors_count; - dbgln("IDEChannel: {} {} {} device found: Name={}, Capacity={}, Capabilities=0x{:04x}", channel_type_string(), channel_string(i), interface_type == PATADiskDevice::InterfaceType::ATA ? "ATA" : "ATAPI", ((char*)bbuf.data() + 54), max_addressable_block * 512, capabilities); + dbgln("IDEChannel: {} {} {} device found: Name={}, Capacity={}, Capabilities={:#04x}", channel_type_string(), channel_string(i), interface_type == PATADiskDevice::InterfaceType::ATA ? "ATA" : "ATAPI", ((char*)bbuf.data() + 54), max_addressable_block * 512, capabilities); if (i == 0) { m_master = PATADiskDevice::create(m_parent_controller, *this, PATADiskDevice::DriveType::Master, interface_type, capabilities, max_addressable_block); } else { diff --git a/Kernel/Thread.cpp b/Kernel/Thread.cpp index 82f9622bc2..7561aae7af 100644 --- a/Kernel/Thread.cpp +++ b/Kernel/Thread.cpp @@ -1160,9 +1160,9 @@ static bool symbolicate(RecognizedSymbol const& symbol, Process& process, String if (auto* region = process.space().find_region_containing({ VirtualAddress(symbol.address), sizeof(FlatPtr) })) { size_t offset = symbol.address - region->vaddr().get(); if (auto region_name = region->name(); !region_name.is_null() && !region_name.is_empty()) - builder.appendff("{:p} {} + 0x{:x}\n", (void*)symbol.address, region_name, offset); + builder.appendff("{:p} {} + {:#x}\n", (void*)symbol.address, region_name, offset); else - builder.appendff("{:p} {:p} + 0x{:x}\n", (void*)symbol.address, region->vaddr().as_ptr(), offset); + builder.appendff("{:p} {:p} + {:#x}\n", (void*)symbol.address, region->vaddr().as_ptr(), offset); } else { builder.appendff("{:p}\n", symbol.address); } @@ -1173,7 +1173,7 @@ static bool symbolicate(RecognizedSymbol const& symbol, Process& process, String if (symbol.symbol->address == g_highest_kernel_symbol_address && offset > 4096) { builder.appendff("{:p}\n", (void*)(mask_kernel_addresses ? 0xdeadc0de : symbol.address)); } else { - builder.appendff("{:p} {} + 0x{:x}\n", (void*)(mask_kernel_addresses ? 0xdeadc0de : symbol.address), symbol.symbol->name, offset); + builder.appendff("{:p} {} + {:#x}\n", (void*)(mask_kernel_addresses ? 0xdeadc0de : symbol.address), symbol.symbol->name, offset); } return true; } diff --git a/Kernel/VM/MemoryManager.cpp b/Kernel/VM/MemoryManager.cpp index 49a3d2d131..cf64cb2e6b 100644 --- a/Kernel/VM/MemoryManager.cpp +++ b/Kernel/VM/MemoryManager.cpp @@ -325,16 +325,16 @@ UNMAP_AFTER_INIT void MemoryManager::parse_memory_map() m_system_memory_info.user_physical_pages_uncommitted = m_system_memory_info.user_physical_pages; for (auto& used_range : m_used_memory_ranges) { - dmesgln("MM: {} range @ {} - {} (size 0x{:x})", UserMemoryRangeTypeNames[to_underlying(used_range.type)], used_range.start, used_range.end.offset(-1), used_range.end.as_ptr() - used_range.start.as_ptr()); + dmesgln("MM: {} range @ {} - {} (size {:#x})", UserMemoryRangeTypeNames[to_underlying(used_range.type)], used_range.start, used_range.end.offset(-1), used_range.end.as_ptr() - used_range.start.as_ptr()); } for (auto& region : m_super_physical_regions) { - dmesgln("MM: Super physical region: {} - {} (size 0x{:x})", region.lower(), region.upper().offset(-1), PAGE_SIZE * region.size()); + dmesgln("MM: Super physical region: {} - {} (size {:#x})", region.lower(), region.upper().offset(-1), PAGE_SIZE * region.size()); region.initialize_zones(); } for (auto& region : m_user_physical_regions) { - dmesgln("MM: User physical region: {} - {} (size 0x{:x})", region.lower(), region.upper().offset(-1), PAGE_SIZE * region.size()); + dmesgln("MM: User physical region: {} - {} (size {:#x})", region.lower(), region.upper().offset(-1), PAGE_SIZE * region.size()); region.initialize_zones(); } } diff --git a/Userland/DevTools/UserspaceEmulator/Emulator_syscalls.cpp b/Userland/DevTools/UserspaceEmulator/Emulator_syscalls.cpp index 63ef464052..dea03f176b 100644 --- a/Userland/DevTools/UserspaceEmulator/Emulator_syscalls.cpp +++ b/Userland/DevTools/UserspaceEmulator/Emulator_syscalls.cpp @@ -852,7 +852,7 @@ u32 Emulator::virt$mmap(u32 params_addr) else { // mmap(nullptr, …, MAP_FIXED) is technically okay, but tends to be a bug. // Therefore, refuse to be helpful. - reportln("\n=={}== \033[31;1mTried to mmap at nullptr with MAP_FIXED.\033[0m, 0x{:x} bytes.", getpid(), params.size); + reportln("\n=={}== \033[31;1mTried to mmap at nullptr with MAP_FIXED.\033[0m, {:#x} bytes.", getpid(), params.size); dump_backtrace(); } } else { diff --git a/Userland/Libraries/LibRegex/RegexByteCode.h b/Userland/Libraries/LibRegex/RegexByteCode.h index ba1d3214a2..c696ace0f8 100644 --- a/Userland/Libraries/LibRegex/RegexByteCode.h +++ b/Userland/Libraries/LibRegex/RegexByteCode.h @@ -510,7 +510,7 @@ public: const String to_string() const { - return String::formatted("[0x{:02X}] {}", (int)opcode_id(), name(opcode_id())); + return String::formatted("[{:#02X}] {}", (int)opcode_id(), name(opcode_id())); } virtual const String arguments_string() const = 0; diff --git a/Userland/Libraries/LibWasm/Parser/Parser.cpp b/Userland/Libraries/LibWasm/Parser/Parser.cpp index b16ea72ada..0560c9e1d5 100644 --- a/Userland/Libraries/LibWasm/Parser/Parser.cpp +++ b/Userland/Libraries/LibWasm/Parser/Parser.cpp @@ -158,7 +158,7 @@ ParseResult FunctionType::parse(InputStream& stream) return with_eof_check(stream, ParseError::ExpectedKindTag); if (tag != Constants::function_signature_tag) { - dbgln("Expected 0x60, but found 0x{:x}", tag); + dbgln("Expected 0x60, but found {:#x}", tag); return with_eof_check(stream, ParseError::InvalidTag); } diff --git a/Userland/Utilities/functrace.cpp b/Userland/Utilities/functrace.cpp index 6cdc9a4389..ac26f7ba36 100644 --- a/Userland/Utilities/functrace.cpp +++ b/Userland/Utilities/functrace.cpp @@ -51,7 +51,7 @@ static void print_syscall(PtraceRegisters& regs, size_t depth) const char* begin_color = g_should_output_color ? "\033[34;1m" : ""; const char* end_color = g_should_output_color ? "\033[0m" : ""; #if ARCH(I386) - outln("=> {}SC_{}(0x{:x}, 0x{:x}, 0x{:x}){}", + outln("=> {}SC_{}({:#x}, {:#x}, {:#x}){}", begin_color, Syscall::to_string((Syscall::Function)regs.eax), regs.edx, @@ -59,7 +59,7 @@ static void print_syscall(PtraceRegisters& regs, size_t depth) regs.ebx, end_color); #else - outln("=> {}SC_{}(0x{:x}, 0x{:x}, 0x{:x}){}", + outln("=> {}SC_{}({:#x}, {:#x}, {:#x}){}", begin_color, Syscall::to_string((Syscall::Function)regs.rax), regs.rdx,