Skip to contentSkip to conversation

x86: small unifications of address printing

PATCH Applied Vegard Nossum 3 participants 6 messages Jul 1, 2008

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86: small unifications of address printing

(resend to lkml)

From: Vegard Nossum <[email protected]>
Date: Tue, 1 Jul 2008 14:51:08 +0200
Subject: [PATCH] x86: small unifications of address printing

'man 3 printf' tells me that %p should be printed as if by %#x, but this is not true for the kernel, which does not use the '0x' prefix for the %p conversion specifier.

A small cast to (void *) is also prettier than #ifdef/#else/#endif.

---
 arch/x86/mm/fault.c |   16 ++++------------
 1 files changed, 4 insertions(+), 12 deletions(-)
arch/x86/mm/fault.c +4 -12
index cd0ea9d..179c159 100644
@@ -409,11 +409,7 @@ static void show_fault_oops(struct pt_regs *regs, unsigned long error_code,
 		printk(KERN_CONT "NULL pointer dereference");
 	else
 		printk(KERN_CONT "paging request");
-#ifdef CONFIG_X86_32
-	printk(KERN_CONT " at %08lx\n", address);
-#else
-	printk(KERN_CONT " at %016lx\n", address);
-#endif
+	printk(KERN_CONT " at %p\n", (void *) address);
 	printk(KERN_ALERT "IP:");
 	printk_address(regs->ip, 1);
 	dump_pagetable(address);
@@ -830,14 +826,10 @@ bad_area_nosemaphore:
 		if (show_unhandled_signals && unhandled_signal(tsk, SIGSEGV) &&
 		    printk_ratelimit()) {
 			printk(
-#ifdef CONFIG_X86_32
-			"%s%s[%d]: segfault at %lx ip %08lx sp %08lx error %lx",
-#else
-			"%s%s[%d]: segfault at %lx ip %lx sp %lx error %lx",
-#endif
+			"%s%s[%d]: segfault at %lx ip %p sp %p error %lx",
 			task_pid_nr(tsk) > 1 ? KERN_INFO : KERN_EMERG,
-			tsk->comm, task_pid_nr(tsk), address, regs->ip,
-			regs->sp, error_code);
+			tsk->comm, task_pid_nr(tsk), address,
+			(void *) regs->ip, (void *) regs->sp, error_code);
 			print_vma_addr(" in ", regs->ip);
 			printk("\n");
 		}
Signature · 1 line
1.5.4.1
#1 lore raw
Quoted 3 lines · Vegard Nossum

'man 3 printf' tells me that %p should be printed as if by %#x, but this is not true for the kernel, which does not use the '0x' prefix for the %p conversion specifier.

Problem is that %p will not pad to 8/16 digits. Addresses are traditionally padded.

-Andi

#2 lore raw
Quoted 8 lines · Andi Kleen
Quoted 3 lines · Vegard Nossum

'man 3 printf' tells me that %p should be printed as if by %#x, but this is not true for the kernel, which does not use the '0x' prefix for the %p conversion specifier.

Problem is that %p will not pad to 8/16 digits. Addresses are traditionally padded.

Yes, it will, and correctly too:

        case 'p':
                flags |= SMALL;
                if (field_width == -1) {
                        field_width = 2*sizeof(void *);
                        flags |= ZEROPAD;
                }

Or did I read this code wrong? field_width is initialized to -1 by default unless overridden. The SMALL flag means lowercase hexadecimal digits.

Vegard

Signature · 4 lines
"The animistic metaphor of the bug that maliciously sneaked in while
the programmer was not looking is intellectually dishonest as it
disguises that the error is the programmer's own creation."
	-- E. W. Dijkstra, EWD1036
#3 lore raw
Quoted 10 lines

Yes, it will, and correctly too:

        case 'p':
                flags |= SMALL;
                if (field_width == -1) {
                        field_width = 2*sizeof(void *);
                        flags |= ZEROPAD;
                }
Quoted 3 lines

Or did I read this code wrong? field_width is initialized to -1 by default unless overridden. The SMALL flag means lowercase hexadecimal digits.

You're right. The kernel differs from user space/traditional behaviour in this regard.

-Andi

#4 lore raw
Quoted 10 lines · Andi Kleen
Quoted 10 lines

Yes, it will, and correctly too:

        case 'p':
                flags |= SMALL;
                if (field_width == -1) {
                        field_width = 2*sizeof(void *);
                        flags |= ZEROPAD;
                }
Quoted 6 lines
Quoted 3 lines

Or did I read this code wrong? field_width is initialized to -1 by default unless overridden. The SMALL flag means lowercase hexadecimal digits.

You're right. The kernel differs from user space/traditional behaviour in this regard.

...in this regard _too_ ;-)

I just ran a short test with glibc, and I'm surprised to see that this implementation is not zero-padding the number.

The C99 standard has this to say:

"The argument shall be a pointer to void. The value of the pointer is converted to a sequence of printing characters, in an implementation-defined manner."

so I suppose it's quite alright after all.

Thanks for looking.

Vegard

Signature · 4 lines
"The animistic metaphor of the bug that maliciously sneaked in while
the programmer was not looking is intellectually dishonest as it
disguises that the error is the programmer's own creation."
	-- E. W. Dijkstra, EWD1036
Applied
#5 lore raw
In reply to Vegard Nossum
Quoted 11 lines · Vegard Nossum

(resend to lkml)

From: Vegard Nossum <[email protected]>
Date: Tue, 1 Jul 2008 14:51:08 +0200
Subject: [PATCH] x86: small unifications of address printing

'man 3 printf' tells me that %p should be printed as if by %#x, but this is not true for the kernel, which does not use the '0x' prefix for the %p conversion specifier.

A small cast to (void *) is also prettier than #ifdef/#else/#endif.

applied to tip/x86/debug - thanks Vegard.

Ingo