From: Nicholas Nethercote Date: Fri, 26 Aug 2005 19:42:27 +0000 (+0000) Subject: Change slightly the way integers are printed by printf() and friends. X-Git-Tag: svn/VALGRIND_3_1_0~514 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ccad5e360062351b203b3f5a75bf144dfc10504e;p=thirdparty%2Fvalgrind.git Change slightly the way integers are printed by printf() and friends. Previously, %d printed a 32-bit int. %ld and %lld printed 64-bit ints. So if you wanted to print a word-sized int (eg. a SizeT variable), you had to cast it to a Long and then print with %lld in order to work on both 32-bit and 64-bit platforms. I changed things so that %d prints a 32-bit int, %ld prints a word-sized int, and %lld prints a 64-bit int. There are two advantages to this: - it now matches the way the normal glibc printf() works; - you can print word-sized ints without casting. I also made the corresponding change for %u/lu/llu and %x/lx/llx, and I changed a couple of VG_(printf)() invocations accordingly. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@4527 --- diff --git a/coregrind/m_aspacemgr/aspacemgr.c b/coregrind/m_aspacemgr/aspacemgr.c index 39e8ca82b7..5b1abba748 100644 --- a/coregrind/m_aspacemgr/aspacemgr.c +++ b/coregrind/m_aspacemgr/aspacemgr.c @@ -741,9 +741,9 @@ VG_(map_file_segment)( Addr addr, SizeT len, VG_(printf)( "\n" "map_file_segment(addr=%p len=%lu prot=0x%x flags=0x%x\n" - " dev=0x%4x ino=%d off=%ld\n" + " dev=0x%4x ino=%d off=%lld\n" " filename='%s')\n", - addr, (ULong)len, prot, flags, dev, ino, off, filename); + addr, len, prot, flags, dev, ino, off, filename); if (0) VG_(show_segments)("before map_file_segment"); diff --git a/coregrind/m_debuglog.c b/coregrind/m_debuglog.c index bdf2769dba..2cde3d9789 100644 --- a/coregrind/m_debuglog.c +++ b/coregrind/m_debuglog.c @@ -384,6 +384,7 @@ VG_(debugLog_vprintf) ( Int i; Int flags; Int width; + Int n_ls = 0; Bool is_long; /* We assume that vargs has already been initialised by the @@ -408,7 +409,7 @@ VG_(debugLog_vprintf) ( continue; } flags = 0; - is_long = False; + n_ls = 0; width = 0; /* length of the field. */ if (format[i] == '(') { flags |= VG_MSG_PAREN; @@ -436,9 +437,16 @@ VG_(debugLog_vprintf) ( } while (format[i] == 'l') { i++; - is_long = True; + n_ls++; } + // %d means print a 32-bit integer. + // %ld means print a word-size integer. + // %lld means print a 64-bit integer. + if (0 == n_ls) { is_long = False; } + else if (1 == n_ls) { is_long = ( sizeof(void*) == sizeof(Long) ); } + else { is_long = True; } + switch (format[i]) { case 'd': /* %d */ flags |= VG_MSG_SIGNED; diff --git a/coregrind/m_syswrap/syswrap-generic.c b/coregrind/m_syswrap/syswrap-generic.c index 15db45409d..94d15f2b15 100644 --- a/coregrind/m_syswrap/syswrap-generic.c +++ b/coregrind/m_syswrap/syswrap-generic.c @@ -2718,7 +2718,7 @@ PRE(sys_fork) PRE(sys_ftruncate) { *flags |= SfMayBlock; - PRINT("sys_ftruncate ( %d, %lld )", ARG1,(ULong)ARG2); + PRINT("sys_ftruncate ( %d, %ld )", ARG1,ARG2); PRE_REG_READ2(long, "ftruncate", unsigned int, fd, unsigned long, length); } diff --git a/coregrind/m_syswrap/syswrap-linux.c b/coregrind/m_syswrap/syswrap-linux.c index 8187a117c4..74282739c6 100644 --- a/coregrind/m_syswrap/syswrap-linux.c +++ b/coregrind/m_syswrap/syswrap-linux.c @@ -456,7 +456,7 @@ PRE(sys_prctl) PRE(sys_sendfile) { *flags |= SfMayBlock; - PRINT("sys_sendfile ( %d, %d, %p, %llu )", ARG1,ARG2,ARG3,(ULong)ARG4); + PRINT("sys_sendfile ( %d, %d, %p, %lu )", ARG1,ARG2,ARG3,ARG4); PRE_REG_READ4(ssize_t, "sendfile", int, out_fd, int, in_fd, vki_off_t *, offset, vki_size_t, count); @@ -473,7 +473,7 @@ POST(sys_sendfile) PRE(sys_sendfile64) { *flags |= SfMayBlock; - PRINT("sendfile64 ( %d, %d, %p, %llu )",ARG1,ARG2,ARG3,(ULong)ARG4); + PRINT("sendfile64 ( %d, %d, %p, %lu )",ARG1,ARG2,ARG3,ARG4); PRE_REG_READ4(ssize_t, "sendfile64", int, out_fd, int, in_fd, vki_loff_t *, offset, vki_size_t, count); @@ -794,7 +794,7 @@ PRE(sys_io_submit) { Int i; - PRINT("sys_io_submit ( %llu, %lld, %p )", (ULong)ARG1,(Long)ARG2,ARG3); + PRINT("sys_io_submit ( %llu, %ld, %p )", (ULong)ARG1,ARG2,ARG3); PRE_REG_READ3(long, "io_submit", vki_aio_context_t, ctx_id, long, nr, struct iocb **, iocbpp); diff --git a/massif/ms_main.c b/massif/ms_main.c index 03fb3361fb..d4d2b6b3b9 100644 --- a/massif/ms_main.c +++ b/massif/ms_main.c @@ -1531,7 +1531,7 @@ static void pp_all_XPts2(Int fd, Queue* q, ULong heap_spacetime, // tl_assert(sum <= xpt->exact_ST_dbld); // tl_assert(sum * 1.05 > xpt->exact_ST_dbld ); // if (sum != xpt->exact_ST_dbld) { -// VG_(printf)("%ld, %ld\n", sum, xpt->exact_ST_dbld); +// VG_(printf)("%lld, %lld\n", sum, xpt->exact_ST_dbld); // } }