Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix printf format strings on 64-bit architectures

Acked-by: Gianluca Guida <glguida@me.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
  • Loading branch information...
commit eb320a5a00f47377caf7771c4779529555b83819 1 parent 48004b9
@penberg penberg authored
View
2  CMakeLists.txt
@@ -72,7 +72,7 @@ ENDMACRO(TARGET_LINK_LLVM)
# Add extra warnings for gcc/g++.
#
IF(CMAKE_COMPILER_IS_GNUCXX)
- ADD_DEFINITIONS(-W -Wall -Wextra -Wno-unused -Werror)
+ ADD_DEFINITIONS(-W -Wall -Wextra -Wno-unused -Werror -D__STDC_FORMAT_MACROS=1)
ENDIF()
FOREACH(ARCHITECTURE ${GUEST_ARCHITECTURES})
View
4 arch/6502/6502_disasm.cpp
@@ -10,6 +10,8 @@
#include "libcpu.h"
#include "6502_isa.h"
+#include <inttypes.h>
+
static const char *addmode_template[] = {
/*[ADDMODE_ABS]*/ "$%04X",
/*[ADDMODE_ABSX]*/ "$%04X,X",
@@ -98,7 +100,7 @@ arch_6502_disasm_instr(cpu_t *cpu, addr_t pc, char *line, unsigned int max_line)
int addmode = get_addmode(opcode);
if (addmode == ADDMODE_BRA) {
- snprintf(line2, sizeof(line2), "$%02llX", pc+2 + (int8_t)cpu->RAM[pc+1]);
+ snprintf(line2, sizeof(line2), "$%02" PRIX64, pc+2 + (int8_t)cpu->RAM[pc+1]);
} else {
switch (get_length(addmode)) {
case 1:
View
4 arch/6502/6502_translate.cpp
@@ -11,6 +11,8 @@
#include "6502_isa.h"
#include "frontend.h"
+#include <inttypes.h>
+
#define A 0
#define X 1
#define Y 2
@@ -105,7 +107,7 @@ arch_6502_trap(cpu_t *cpu, addr_t pc, BasicBlock *bb)
Value *
arch_6502_translate_cond(cpu_t *cpu, addr_t pc, BasicBlock *bb) {
uint8_t opcode = cpu->RAM[pc];
-LOG("%s:%d pc=%llx opcode=%x\n", __func__, __LINE__, pc, opcode);
+LOG("%s:%d pc=%" PRIx64 " opcode=%x\n", __func__, __LINE__, pc, opcode);
switch (get_instr(opcode)) {
case INSTR_BEQ: /* Z */ return CC_EQ;
View
4 arch/arm/arm_translate.cpp
@@ -13,6 +13,8 @@
#include "arm_types.h"
#include "tag.h"
+#include <inttypes.h>
+
using namespace llvm;
#define ptr_N ((ccarm_t*)cpu->feptr)->ptr_N
@@ -186,7 +188,7 @@ setsub(cpu_t *cpu, Value *op1, Value *op2, BasicBlock *bb)
#define LINK LET32(14, CONST((uint64_t)(sint64_t)(sint32_t)pc+8))
int arch_arm_translate_instr(cpu_t *cpu, addr_t pc, BasicBlock *bb) {
-LOG("%s:%d pc=%llx\n", __func__, __LINE__, pc);
+LOG("%s:%d pc=%" PRIx64 "\n", __func__, __LINE__, pc);
uint32_t instr = *(uint32_t*)&cpu->RAM[pc];
// int cond = instr >> 28;
View
6 arch/fapra/fapra_translate.cpp
@@ -7,6 +7,8 @@
#include "frontend.h"
#include "fapra_internal.h"
+#include <inttypes.h>
+
using namespace llvm;
//////////////////////////////////////////////////////////////////////
@@ -155,7 +157,7 @@ arch_fapra_translate_cond(cpu_t *cpu, addr_t pc, BasicBlock *bb)
{
uint32_t instr = INSTR(pc);
- LOG("cond (%08llx) %08x\n", pc, instr);
+ LOG("cond (%08" PRIx64 ") %08x\n", pc, instr);
switch (opc(instr)) {
default:
@@ -179,7 +181,7 @@ arch_fapra_translate_instr(cpu_t *cpu, addr_t pc, BasicBlock *bb)
uint32_t instr = INSTR(pc);
- LOG("translating (%08llx) %08x\n", pc, instr);
+ LOG("translating (%08" PRIx64 ") %08x\n", pc, instr);
switch (opc(instr)) {
case PERM:
View
26 arch/m68k/m68k_disasm.cpp
@@ -4,6 +4,8 @@
#include "libcpu.h"
#include "m68k_isa.h"
+#include <inttypes.h>
+
enum {
TASK_DIS,
TASK_REC,
@@ -132,7 +134,7 @@ decodeimm(cpu_t *cpu, addr_t pc, int size) {
case SIZE_L:
return RAM32(pc+2);
}
- printf("decodeimm pc=%llx", pc);
+ printf("decodeimm pc=%" PRIx64, pc);
exit(1);
return 0;
}
@@ -200,8 +202,8 @@ decodemodreg(int task, cpu_t *cpu, addr_t pc, int size, int mod, int reg, char *
return;
}
if (reg == 2) {
- DIS snprintf(op1, maxop, "0x%08llx", RAM16(pc+2)+pc+2);
- REC snprintf(op1, maxop, "RAM%d,0x%llx", sizenum[size], RAM16(pc+2)+pc+2);
+ DIS snprintf(op1, maxop, "0x%08" PRIx64, RAM16(pc+2)+pc+2);
+ REC snprintf(op1, maxop, "RAM%d,0x%" PRIx64, sizenum[size], RAM16(pc+2)+pc+2);
REC *rm=IS_MEM;
return;
}
@@ -343,19 +345,19 @@ disreclen(int task, cpu_t *cpu, addr_t pc, char *line, unsigned int max_line, ad
decodemodreg(task, cpu, pc, SIZE_L, MOD0, REG0, op1, sizeof(op1), &attr, &rm);
DIS snprintf(line, max_line, "jsr %s", op1);
len = 2+lengthmodreg(MOD0, REG0, 0);
- REC snprintf(line, max_line, "call (READ_%s,0x%08llx);", op1, pc+len);
+ REC snprintf(line, max_line, "call (READ_%s,0x%08" PRIx64 ");", op1, pc+len);
break;
} else if (bits(opcode,0,7) == 0x56) { /* LINKW */ // 68030?
decodemodreg(task, cpu, pc, SIZE_L, MOD0, REG0, op1, sizeof(op1), &attr, &rm);
DIS snprintf(line, max_line, "linkw %s, %04x", op1, decodeimm(cpu, pc, SIZE_W));
len = 4+lengthmodreg(MOD0, REG0, 0);
- REC snprintf(line, max_line, "linkw (READ_%s,0x%08llx);", op1, pc+len);
+ REC snprintf(line, max_line, "linkw (READ_%s,0x%08" PRIx64 ");", op1, pc+len);
break;
} else if (bits(opcode,0,7) == 0x5e) { /* UNLK */ // 68030?
decodemodreg(task, cpu, pc, SIZE_L, MOD0, REG0, op1, sizeof(op1), &attr, &rm);
DIS snprintf(line, max_line, "unlk %s", op1);
len = 2+lengthmodreg(MOD0, REG0, 0);
- REC snprintf(line, max_line, "linkw (READ_%s,0x%08llx);", op1, pc+len);
+ REC snprintf(line, max_line, "linkw (READ_%s,0x%08" PRIx64 ");", op1, pc+len);
break;
} else {
// DIS snprintf(line, max_line, "??? opcode %04x (%x)", opcode, bits(opcode,12,15));
@@ -394,13 +396,13 @@ disreclen(int task, cpu_t *cpu, addr_t pc, char *line, unsigned int max_line, ad
case 5:
if (bits(opcode,6,7)==3) {
if (MOD0==1) { /* DBcc */
- DIS snprintf(line, max_line, "db%s d%d, 0x%08llx", condstr_db[CONDITION], REG0, pc+2+RAM16(pc+2));
- REC snprintf(line, max_line, "db%s (d[%d], l%llX);", condstr_db[CONDITION], REG0, pc+2+RAM16(pc+2));
+ DIS snprintf(line, max_line, "db%s d%d, 0x%08" PRIx64, condstr_db[CONDITION], REG0, pc+2+RAM16(pc+2));
+ REC snprintf(line, max_line, "db%s (d[%d], l%" PRIX64 ");", condstr_db[CONDITION], REG0, pc+2+RAM16(pc+2));
len = 4;
}
else if (MOD0==7) { /* TRAPcc */
- DIS snprintf(line, max_line, "trap%s d%d, 0x%08llx", condstr_db[CONDITION], REG0, pc+2+RAM16(pc+2));
- REC snprintf(line, max_line, "trap%s (d[%d], l%llX);", condstr_db[CONDITION], REG0, pc+2+RAM16(pc+2));
+ DIS snprintf(line, max_line, "trap%s d%d, 0x%08" PRIx64, condstr_db[CONDITION], REG0, pc+2+RAM16(pc+2));
+ REC snprintf(line, max_line, "trap%s (d[%d], l%" PRIX64 ");", condstr_db[CONDITION], REG0, pc+2+RAM16(pc+2));
// TODO: decode OPMODE etc.! (p. 8.16 68kPM), optional word or long word
len = 2;
}
@@ -418,8 +420,8 @@ disreclen(int task, cpu_t *cpu, addr_t pc, char *line, unsigned int max_line, ad
break;
case 6: /* Bcc */
disp = arch_disasm_get_disp(cpu, pc, opcode);
- DIS snprintf(line, max_line, "b%s 0x%08llx", condstr[CONDITION], pc+2+disp);
- DIS snprintf(line, max_line, "b%s (l%llX);", condstr[CONDITION], pc+2+disp);
+ DIS snprintf(line, max_line, "b%s 0x%08" PRIx64, condstr[CONDITION], pc+2+disp);
+ DIS snprintf(line, max_line, "b%s (l%" PRIX64 ");", condstr[CONDITION], pc+2+disp);
len = lengthdisp(cpu, pc, opcode);
break;
case 7:
View
4 arch/m88k/m88k_translate.cpp
@@ -6,6 +6,8 @@
#include "m88k_internal.h"
#include "m88k_insn.h"
+#include <inttypes.h>
+
using namespace llvm;
#define ptr_PSR ptr_xr[0]
@@ -737,7 +739,7 @@ arch_m88k_xmem(cpu_t *cpu, bool byte, m88k_reg_t rd, Value *src1, Value *src2, B
int
arch_m88k_translate_instr(cpu_t *cpu, addr_t pc, BasicBlock *bb)
{
-#define BAD do { printf("%s:%u: BAD INSTRUCTION AT PC %llx\n", __func__, __LINE__, pc); exit(1); } while(0)
+#define BAD do { printf("%s:%u: BAD INSTRUCTION AT PC %" PRIu64 "\n", __func__, __LINE__, pc); exit(1); } while(0)
#define LOGX LOG("%s:%d PC=%llx\n", __func__, __LINE__, pc);
m88k_insn instr = INSTR(pc);
m88k_opcode_t opc = instr.opcode();
View
6 arch/mips/mips_translate.cpp
@@ -7,6 +7,8 @@
#include "frontend.h"
#include "mips_internal.h"
+#include <inttypes.h>
+
using namespace llvm;
//////////////////////////////////////////////////////////////////////
@@ -288,7 +290,7 @@ arch_mips_translate_cond(cpu_t *cpu, addr_t pc, BasicBlock *bb)
{
uint32_t instr = INSTR(pc);
- LOG("cond (%08llx) %08x\n", pc, instr);
+ LOG("cond (%08" PRIx64 ") %08x\n", pc, instr);
switch(instr >> 26) {
case 0x01: /* INCPU_REGIMM */
@@ -328,7 +330,7 @@ arch_mips_translate_instr(cpu_t *cpu, addr_t pc, BasicBlock *bb)
uint32_t instr = INSTR(pc);
- LOG("translating (%08llx) %08x\n", pc, instr);
+ LOG("translating (%08" PRIx64 ") %08x\n", pc, instr);
switch(instr >> 26) {
case 0x00: /* INCPU_SPECIAL */
View
4 libcpu/basicblock.cpp
@@ -13,6 +13,8 @@
#include "basicblock.h"
#include "tag.h"
+#include <inttypes.h>
+
bool
is_start_of_basicblock(cpu_t *cpu, addr_t a)
{
@@ -63,7 +65,7 @@ lookup_basicblock(cpu_t *cpu, Function* f, addr_t pc, BasicBlock *bb_ret, uint8_
if (i != bb_addr.end())
return i->second;
- LOG("basic block %c%08llx not found in function %p - creating return basic block!\n", bb_type, pc, f);
+ LOG("basic block %c%08" PRIx64 " not found in function %p - creating return basic block!\n", bb_type, pc, f);
BasicBlock *new_bb = create_basicblock(cpu, pc, cpu->cur_func, BB_TYPE_EXTERNAL);
emit_store_pc_return(cpu, new_bb, pc, bb_ret);
View
25 libcpu/idbg.cpp
@@ -49,6 +49,7 @@
#include <assert.h>
#include <ctype.h>
#include <stddef.h>
+#include <inttypes.h>
#ifdef USE_READLINE
#define Function FunctionX // XXX clash in readline.
@@ -143,11 +144,11 @@ idbg_print_int_value(uint64_t v, unsigned bits, int align, unsigned mode)
case M_SIGNED:
if (bits != 64 && (v & (1ULL << (bits - 1))) != 0)
v |= -1ULL << bits;
- fprintf(stdout, "%lld", (int64_t)v);
+ fprintf(stdout, "%" PRId64 , (int64_t)v);
break;
case M_UNSIGNED:
- fprintf(stdout, "%llu", v);
+ fprintf(stdout, "%" PRIu64, v);
break;
case M_BIN:
@@ -158,18 +159,18 @@ idbg_print_int_value(uint64_t v, unsigned bits, int align, unsigned mode)
if (align < 0)
align = ALIGN8(bits) / 3;
if (align == 0)
- fprintf(stdout, "0%llo", v);
+ fprintf(stdout, "0%" PRIo64, v);
else
- fprintf(stdout, "0%.*llo", align, v);
+ fprintf(stdout, "0%.*" PRIo64, align, v);
break;
case M_HEX:
if (align < 0)
align = ALIGN8(bits) >> 2;
if (align == 0)
- fprintf(stdout, "0x%llx", v);
+ fprintf(stdout, "0x%" PRIx64, v);
else
- fprintf(stdout, "0x%.*llx", align, v);
+ fprintf(stdout, "0x%.*" PRIx64, align, v);
break;
}
}
@@ -186,7 +187,7 @@ idbg_print_qword(uint64_t const *v, unsigned mode, int)
idbg_print_bits(v[0], 64);
idbg_print_bits(v[1], 64);
} else
- fprintf(stdout, "0x%016llx%016llx", v[0], v[1]);
+ fprintf(stdout, "0x%016" PRIx64 "%016" PRIx64 "", v[0], v[1]);
}
static void
@@ -252,7 +253,7 @@ static inline void
idbg_print_float64(uint64_t v, bool hex)
{
if (hex)
- fprintf(stdout, "%f [%016llx]", *(double *)&v, v);
+ fprintf(stdout, "%f [%016" PRIx64 "]", *(double *)&v, v);
else
fprintf(stdout, "%f", *(double *)&v);
}
@@ -260,13 +261,13 @@ idbg_print_float64(uint64_t v, bool hex)
static inline void
idbg_print_float80(uint64_t const *v, bool hex)
{
- fprintf(stdout, "[%04llx%016llx]", v[0], v[1]);
+ fprintf(stdout, "[%04" PRIx64 "%016" PRIx64 "]", v[0], v[1]);
}
static inline void
idbg_print_float128(uint64_t const *v, bool hex)
{
- fprintf(stdout, "[%016llx%016llx]", v[0], v[1]);
+ fprintf(stdout, "[%016" PRIx64 "%016" PRIx64 "]", v[0], v[1]);
}
//////////////////////////////////////////////////////////////////////////////
@@ -719,7 +720,7 @@ idbg_diff_registers(idbg_t *ctx)
idbg_print_address(ctx, ctx->saved_regs[n]);
fprintf(stdout, " -> ");
idbg_print_address(ctx, v);
- fprintf(stdout, " (delta %lld)\n",
+ fprintf(stdout, " (delta %" PRId64 ")\n",
v - ctx->saved_regs[n]);
}
}
@@ -833,7 +834,7 @@ idbg_examine(idbg_t *ctx, addr_t address, size_t count,
ptrdiff_t bytes = idbg_examine_one(ctx, address, format, mode);
if (bytes < 0) {
- fprintf(stderr, "\nIDBG ERROR: Cannot access address %llx.\n",
+ fprintf(stderr, "\nIDBG ERROR: Cannot access address %" PRIx64 ".\n",
address);
break;
}
View
11 libcpu/interface.cpp
@@ -6,6 +6,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <inttypes.h>
#include "llvm/Analysis/Verifier.h"
#include "llvm/ExecutionEngine/JIT.h"
@@ -376,7 +377,7 @@ cpu_run(cpu_t *cpu, debug_function_t debug_function)
}
}
if (!success) {
- LOG("{%llx}", pc);
+ LOG("{%" PRIx64 "}", pc);
cpu_tag(cpu, pc);
do_translate = true;
}
@@ -402,9 +403,9 @@ cpu_flush(cpu_t *cpu)
void
cpu_print_statistics(cpu_t *cpu)
{
- printf("tag = %8lld\n", cpu->timer_total[TIMER_TAG]);
- printf("fe = %8lld\n", cpu->timer_total[TIMER_FE]);
- printf("be = %8lld\n", cpu->timer_total[TIMER_BE]);
- printf("run = %8lld\n", cpu->timer_total[TIMER_RUN]);
+ printf("tag = %8" PRId64 "\n", cpu->timer_total[TIMER_TAG]);
+ printf("fe = %8" PRId64 "\n", cpu->timer_total[TIMER_FE]);
+ printf("be = %8" PRId64 "\n", cpu->timer_total[TIMER_BE]);
+ printf("run = %8" PRId64 "\n", cpu->timer_total[TIMER_RUN]);
}
//printf("%s:%d\n", __func__, __LINE__);
Please sign in to comment.
Something went wrong with that request. Please try again.