瀏覽代碼

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.
Gunnar Beutner 4 年之前
父節點
當前提交
36e36507d5

+ 3 - 3
Kernel/Bus/PCI/Access.cpp

@@ -442,13 +442,13 @@ OwnPtr<KBuffer> 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();

+ 1 - 1
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;

+ 1 - 1
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);
     }
 }
 

+ 2 - 2
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());

+ 4 - 4
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<SpinLock<u8>>& main_lock)
 {
     VERIFY(m_lock.is_locked());
-    dbgln_if(AHCI_DEBUG, "AHCI Port {}: Initialization. Signature = 0x{:08x}", representative_port_index(), static_cast<u32>(m_port_registers.sig));
+    dbgln_if(AHCI_DEBUG, "AHCI Port {}: Initialization. Signature = {:#08x}", representative_port_index(), static_cast<u32>(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<SpinLock<u8>>& 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;
             }

+ 1 - 1
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 {

+ 3 - 3
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;
 }

+ 3 - 3
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();
     }
 }

+ 1 - 1
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 {

+ 1 - 1
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;

+ 1 - 1
Userland/Libraries/LibWasm/Parser/Parser.cpp

@@ -158,7 +158,7 @@ ParseResult<FunctionType> 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);
     }
 

+ 2 - 2
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,