V4: fix address printing for real.
authorErik Verbruggen <erik.verbruggen@digia.com>
Fri, 7 Mar 2014 13:33:56 +0000 (14:33 +0100)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Sat, 8 Mar 2014 08:26:40 +0000 (09:26 +0100)
The previous patch contained the wrong formatting string for 64bit
platforms. Good compilers will warn on this (and fail compiling with
-Werror). Fixed the issue in such a way that we now have static checking
for both 32bit/64bit platforms by the compiler.

Change-Id: Idf4a80d8795605c61ef812426c9984df1ceac4d4
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
src/3rdparty/masm/disassembler/UDis86Disassembler.cpp

index 3d9d8cb..b01a234 100644 (file)
 
 namespace JSC {
 
+namespace {
+template <int> struct helper;
+template <> struct helper<4> {
+    static void hex(char *str, size_t len, uint64_t pc)
+    { snprintf(str, len, "0x%x", static_cast<uint32_t>(pc)); }
+};
+template <> struct helper<8> {
+    static void hex(char *str, size_t len, uint64_t pc)
+    { snprintf(str, len, "0x%llx", pc); }
+};
+inline void print(char *str, size_t len, uint64_t pc)
+{ helper<sizeof(void*)>::hex(str, len, pc); }
+}
+
 bool tryToDisassemble(const MacroAssemblerCodePtr& codePtr, size_t size, const char* prefix, PrintStream& out)
 {
     ud_t disassembler;
@@ -49,13 +63,7 @@ bool tryToDisassemble(const MacroAssemblerCodePtr& codePtr, size_t size, const c
     uint64_t currentPC = disassembler.pc;
     while (ud_disassemble(&disassembler)) {
         char pcString[20];
-        snprintf(pcString, sizeof(pcString),
-#if OS(WINDOWS)
-                 "0x%p",
-#else
-                 "%p",
-#endif
-                 currentPC);
+        print(pcString, sizeof(pcString), currentPC);
         out.printf("%s%16s: %s\n", prefix, pcString, ud_insn_asm(&disassembler));
         currentPC = disassembler.pc;
     }