LLP64: adjust calls to printf-like functions with pointer arguments
authorDavid Lichteblau <david@lichteblau.com>
Mon, 12 Nov 2012 15:19:58 +0000 (16:19 +0100)
committerDavid Lichteblau <david@lichteblau.com>
Tue, 20 Nov 2012 14:01:26 +0000 (15:01 +0100)
For the benefit of LLP64 platforms, do not cast to long when printing a
pointer, and use %p instead of %lx.  If casting is required, cast to
a pointer-sized unsigned integer, not signed long.

Thanks to Anton Kovalenko.

src/runtime/backtrace.c
src/runtime/coreparse.c
src/runtime/gc-common.c
src/runtime/interrupt.c
src/runtime/monitor.c
src/runtime/save.c

index 1d9b506..8345837 100644 (file)
@@ -560,9 +560,9 @@ backtrace_from_fp(void *fp, int nframes)
                    (unsigned long) ra);
         } else
 #endif
-        printf("Foreign fp = 0x%lx, ra = 0x%lx",
-               (unsigned long) next_fp,
-               (unsigned long) ra);
+        printf("Foreign fp = 0x%p, ra = 0x%p",
+               (void*) next_fp,
+               (void*) ra);
     }
 
     putchar('\n');
index fefa834..9dc3157 100644 (file)
@@ -295,7 +295,7 @@ process_directory(int fd, lispobj *ptr, int count, os_vm_offset_t file_offset)
         if (len != 0) {
             os_vm_address_t real_addr;
             FSHOW((stderr, "/mapping %ld(0x%lx) bytes at 0x%lx\n",
-                   (long)len, (long)len, (unsigned long)addr));
+                   len, len, (unsigned long)addr));
             if (compressed) {
 #ifdef LISP_FEATURE_SB_CORE_COMPRESSION
                 real_addr = inflate_core_bytes(fd, offset + file_offset, addr, len);
@@ -333,22 +333,22 @@ process_directory(int fd, lispobj *ptr, int count, os_vm_offset_t file_offset)
                 fprintf(stderr,
                         "dynamic space too small for core: %ldKiB required, %ldKiB available.\n",
                         len >> 10,
-                        (long)dynamic_space_size >> 10);
+                        (uword_t)dynamic_space_size >> 10);
                 exit(1);
             }
 #ifdef LISP_FEATURE_GENCGC
             if (addr != (os_vm_address_t)DYNAMIC_SPACE_START) {
-                fprintf(stderr, "in core: 0x%lx; in runtime: 0x%lx \n",
-                        (long)addr, (long)DYNAMIC_SPACE_START);
+                fprintf(stderr, "in core: 0x%p; in runtime: 0x%p \n",
+                        (uword_t)addr, (uword_t)DYNAMIC_SPACE_START);
                 lose("core/runtime address mismatch: DYNAMIC_SPACE_START\n");
             }
 #else
             if ((addr != (os_vm_address_t)DYNAMIC_0_SPACE_START) &&
                 (addr != (os_vm_address_t)DYNAMIC_1_SPACE_START)) {
-                fprintf(stderr, "in core: 0x%lx; in runtime: 0x%lx or 0x%lx\n",
-                        (long)addr,
-                        (long)DYNAMIC_0_SPACE_START,
-                        (long)DYNAMIC_1_SPACE_START);
+                fprintf(stderr, "in core: 0x%p; in runtime: 0x%p or 0x%p\n",
+                        (uword_t)addr,
+                        (uword_t)DYNAMIC_0_SPACE_START,
+                        (uword_t)DYNAMIC_1_SPACE_START);
                 lose("warning: core/runtime address mismatch: DYNAMIC_SPACE_START\n");
             }
 #endif
@@ -365,20 +365,20 @@ process_directory(int fd, lispobj *ptr, int count, os_vm_offset_t file_offset)
             break;
         case STATIC_CORE_SPACE_ID:
             if (addr != (os_vm_address_t)STATIC_SPACE_START) {
-                fprintf(stderr, "in core: 0x%lx - in runtime: 0x%lx\n",
-                        (long)addr, (long)STATIC_SPACE_START);
+                fprintf(stderr, "in core: 0x%p - in runtime: 0x%p\n",
+                        (uword_t)addr, (uword_t)STATIC_SPACE_START);
                 lose("core/runtime address mismatch: STATIC_SPACE_START\n");
             }
             break;
         case READ_ONLY_CORE_SPACE_ID:
             if (addr != (os_vm_address_t)READ_ONLY_SPACE_START) {
-                fprintf(stderr, "in core: 0x%lx - in runtime: 0x%lx\n",
-                        (long)addr, (long)READ_ONLY_SPACE_START);
+                fprintf(stderr, "in core: 0x%p - in runtime: 0x%p\n",
+                        (uword_t)addr, (uword_t)READ_ONLY_SPACE_START);
                 lose("core/runtime address mismatch: READ_ONLY_SPACE_START\n");
             }
             break;
         default:
-            lose("unknown space ID %ld addr 0x%lx\n", id, (long)addr);
+            lose("unknown space ID %ld addr 0x%p\n", id, addr);
         }
     }
 }
index 1fe6400..c5ff999 100644 (file)
@@ -1716,7 +1716,7 @@ scav_vector (lispobj *where, lispobj object)
          * sets the header in %%PUTHASH.
          */
         fprintf(stderr,
-                "Warning: no pointer at %lx in hash table: this indicates "
+                "Warning: no pointer at %p in hash table: this indicates "
                 "non-fatal corruption caused by concurrent access to a "
                 "hash-table from multiple threads. Any accesses to "
                 "hash-tables shared between threads should be protected "
index 447df7b..27ab564 100644 (file)
@@ -989,7 +989,7 @@ interrupt_handle_pending(os_context_t *context)
          * an interrupt arrived during GC (POST-GC, really) it was
          * handled. */
         if (original_pending_handler != data->pending_handler)
-            lose("pending handler changed in gc: %x -> %d.",
+            lose("pending handler changed in gc: %x -> %x.",
                  original_pending_handler, data->pending_handler);
     }
 
index 9ae58cd..e663074 100644 (file)
@@ -138,7 +138,7 @@ dump_cmd(char **ptr)
 
     while (count-- > 0) {
 #ifndef LISP_FEATURE_ALPHA
-        printf("0x%08lX: ", (unsigned long) addr);
+        printf("0x%p: ", (os_vm_address_t) addr);
 #else
         printf("0x%08X: ", (u32) addr);
 #endif
@@ -190,13 +190,13 @@ regs_cmd(char **ptr)
 {
     struct thread *thread=arch_os_get_current_thread();
 
-    printf("CSP\t=\t0x%08lx   ", (unsigned long)access_control_stack_pointer(thread));
+    printf("CSP\t=\t0x%p   ", access_control_stack_pointer(thread));
 #if !defined(LISP_FEATURE_X86) && !defined(LISP_FEATURE_X86_64)
-    printf("CFP\t=\t0x%08lx   ", (unsigned long)access_control_frame_pointer(thread));
+    printf("CFP\t=\t0x%p   ", access_control_frame_pointer(thread));
 #endif
 
 #ifdef reg_BSP
-    printf("BSP\t=\t0x%08lx\n", (unsigned long)get_binding_stack_pointer(thread));
+    printf("BSP\t=\t0x%p\n", get_binding_stack_pointer(thread));
 #else
     /* printf("BSP\t=\t0x%08lx\n",
            (unsigned long)SymbolValue(BINDING_STACK_POINTER)); */
@@ -206,8 +206,8 @@ regs_cmd(char **ptr)
 #ifdef LISP_FEATURE_GENCGC
     /* printf("DYNAMIC\t=\t0x%08lx\n", DYNAMIC_SPACE_START); */
 #else
-    printf("STATIC\t=\t0x%08lx   ",
-           (unsigned long)SymbolValue(STATIC_SPACE_FREE_POINTER, thread));
+    printf("STATIC\t=\t0x%p   ",
+           SymbolValue(STATIC_SPACE_FREE_POINTER, thread));
     printf("RDONLY\t=\t0x%08lx   ",
            (unsigned long)SymbolValue(READ_ONLY_SPACE_FREE_POINTER, thread));
     printf("DYNAMIC\t=\t0x%08lx\n", (unsigned long)current_dynamic_space);
@@ -266,10 +266,10 @@ search_cmd(char **ptr)
     start = end = addr;
     lastcount = count;
 
-    printf("searching for 0x%x at 0x%08lX\n", val, (unsigned long)end);
+    printf("searching for 0x%x at 0x%p\n", val, (void*)(unsigned long)end);
 
     while (search_for_type(val, &end, &count)) {
-        printf("found 0x%x at 0x%08lX:\n", val, (unsigned long)end);
+        printf("found 0x%x at 0x%p:\n", val, (void*)(unsigned long)end);
         obj = *end;
         addr = end;
         end += 2;
index 1dc6918..8478e1d 100644 (file)
@@ -190,8 +190,8 @@ output_space(FILE *file, int id, lispobj *addr, lispobj *end,
 
     bytes = words * sizeof(lispobj);
 
-    printf("writing %lu bytes from the %s space at 0x%08lx\n",
-           (unsigned long)bytes, names[id], (unsigned long)addr);
+    printf("writing %lu bytes from the %s space at 0x%p\n",
+           bytes, names[id], addr);
 
     data = write_and_compress_bytes(file, (char *)addr, bytes, file_offset,
                                     core_compression_level);