njn | 36a20fa | 2005-06-03 03:08:39 +0000 | [diff] [blame] | 1 | |
| 2 | /*--------------------------------------------------------------------*/ |
| 3 | /*--- Printing libc stuff. pub_tool_libcprint.h ---*/ |
| 4 | /*--------------------------------------------------------------------*/ |
| 5 | |
| 6 | /* |
| 7 | This file is part of Valgrind, a dynamic binary instrumentation |
| 8 | framework. |
| 9 | |
sewardj | 4d474d0 | 2008-02-11 11:34:59 +0000 | [diff] [blame] | 10 | Copyright (C) 2000-2008 Julian Seward |
njn | 36a20fa | 2005-06-03 03:08:39 +0000 | [diff] [blame] | 11 | jseward@acm.org |
| 12 | |
| 13 | This program is free software; you can redistribute it and/or |
| 14 | modify it under the terms of the GNU General Public License as |
| 15 | published by the Free Software Foundation; either version 2 of the |
| 16 | License, or (at your option) any later version. |
| 17 | |
| 18 | This program is distributed in the hope that it will be useful, but |
| 19 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 21 | General Public License for more details. |
| 22 | |
| 23 | You should have received a copy of the GNU General Public License |
| 24 | along with this program; if not, write to the Free Software |
| 25 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 26 | 02111-1307, USA. |
| 27 | |
| 28 | The GNU General Public License is contained in the file COPYING. |
| 29 | */ |
| 30 | |
| 31 | #ifndef __PUB_TOOL_LIBCPRINT_H |
| 32 | #define __PUB_TOOL_LIBCPRINT_H |
| 33 | |
bart | fe101bf | 2008-03-17 18:57:03 +0000 | [diff] [blame] | 34 | |
bart | a0b6b2c | 2008-07-07 06:49:24 +0000 | [diff] [blame] | 35 | /* Enable compile-time format string checking by gcc. |
bart | fe101bf | 2008-03-17 18:57:03 +0000 | [diff] [blame] | 36 | This feature is supported since at least gcc version 2.95. |
| 37 | For more information about the format attribute, see also |
| 38 | http://gcc.gnu.org/onlinedocs/gcc-4.3.0/gcc/Function-Attributes.html. |
| 39 | */ |
| 40 | |
bart | a0b6b2c | 2008-07-07 06:49:24 +0000 | [diff] [blame] | 41 | #if defined(__GNUC__) |
bart | fe101bf | 2008-03-17 18:57:03 +0000 | [diff] [blame] | 42 | #define PRINTF_CHECK(x, y) __attribute__((format(__printf__, x, y))) |
| 43 | #else |
| 44 | #define PRINTF_CHECK(x, y) |
| 45 | #endif |
| 46 | |
| 47 | |
njn | 36a20fa | 2005-06-03 03:08:39 +0000 | [diff] [blame] | 48 | /* --------------------------------------------------------------------- |
| 49 | Basic printing |
| 50 | ------------------------------------------------------------------ */ |
| 51 | |
| 52 | /* Note that they all output to the file descriptor given by the |
| 53 | * --log-fd/--log-file/--log-socket argument, which defaults to 2 (stderr). |
| 54 | * Hence no need for VG_(fprintf)(). |
| 55 | */ |
bart | fe101bf | 2008-03-17 18:57:03 +0000 | [diff] [blame] | 56 | extern UInt VG_(printf) ( const HChar *format, ... ) PRINTF_CHECK(1, 2); |
| 57 | extern UInt VG_(vprintf) ( const HChar *format, va_list vargs ) PRINTF_CHECK(1, 0); |
| 58 | extern UInt VG_(sprintf) ( Char* buf, const HChar* format, ... ) PRINTF_CHECK(2, 3); |
| 59 | extern UInt VG_(vsprintf) ( Char* buf, const HChar* format, va_list vargs ) PRINTF_CHECK(2, 0); |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 60 | extern UInt VG_(snprintf) ( Char* buf, Int size, |
bart | fe101bf | 2008-03-17 18:57:03 +0000 | [diff] [blame] | 61 | const HChar *format, ... ) PRINTF_CHECK(3, 4); |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 62 | extern UInt VG_(vsnprintf)( Char* buf, Int size, |
bart | fe101bf | 2008-03-17 18:57:03 +0000 | [diff] [blame] | 63 | const HChar *format, va_list vargs ) PRINTF_CHECK(3, 0); |
njn | 36a20fa | 2005-06-03 03:08:39 +0000 | [diff] [blame] | 64 | |
njn | 7a5915e | 2005-07-17 16:12:59 +0000 | [diff] [blame] | 65 | // Percentify n/m with d decimal places. Includes the '%' symbol at the end. |
njn | 5eaff2f | 2005-09-25 19:11:45 +0000 | [diff] [blame] | 66 | // Right justifies in 'buf'. |
| 67 | extern void VG_(percentify)(ULong n, ULong m, UInt d, Int n_buf, char buf[]); |
njn | 856c54e | 2005-06-26 18:43:40 +0000 | [diff] [blame] | 68 | |
njn | 36a20fa | 2005-06-03 03:08:39 +0000 | [diff] [blame] | 69 | /* --------------------------------------------------------------------- |
| 70 | Messages for the user |
| 71 | ------------------------------------------------------------------ */ |
| 72 | |
njn | 3e11452 | 2005-06-11 03:31:09 +0000 | [diff] [blame] | 73 | /* No, really. I _am_ that strange. */ |
| 74 | #define OINK(nnn) VG_(message)(Vg_DebugMsg, "OINK %d",nnn) |
| 75 | |
njn | 36a20fa | 2005-06-03 03:08:39 +0000 | [diff] [blame] | 76 | /* Print a message prefixed by "??<pid>?? "; '?' depends on the VgMsgKind. |
| 77 | Should be used for all user output. */ |
| 78 | |
| 79 | typedef |
| 80 | enum { Vg_UserMsg, /* '?' == '=' */ |
| 81 | Vg_DebugMsg, /* '?' == '-' */ |
| 82 | Vg_DebugExtraMsg, /* '?' == '+' */ |
| 83 | Vg_ClientMsg /* '?' == '*' */ |
| 84 | } |
| 85 | VgMsgKind; |
| 86 | |
bart | a0b6b2c | 2008-07-07 06:49:24 +0000 | [diff] [blame] | 87 | /* Send a single-part message. Appends a newline. The format |
| 88 | specification may contain any ISO C format specifier or %t. |
| 89 | No attempt is made to let the compiler verify consistency of the |
| 90 | format string and the argument list. */ |
| 91 | extern UInt VG_(message_no_f_c)( VgMsgKind kind, const HChar* format, ... ); |
| 92 | /* Send a single-part message. Appends a newline. The format |
| 93 | specification may contain any ISO C format specifier. The gcc compiler |
| 94 | will verify consistency of the format string and the argument list. */ |
| 95 | extern UInt VG_(message)( VgMsgKind kind, const HChar* format, ... ) |
| 96 | PRINTF_CHECK(2, 3); |
njn | 36a20fa | 2005-06-03 03:08:39 +0000 | [diff] [blame] | 97 | |
bart | a0b6b2c | 2008-07-07 06:49:24 +0000 | [diff] [blame] | 98 | extern UInt VG_(vmessage)( VgMsgKind kind, const HChar* format, va_list vargs ) |
| 99 | PRINTF_CHECK(2, 0); |
| 100 | |
| 101 | |
| 102 | |
njn | 36a20fa | 2005-06-03 03:08:39 +0000 | [diff] [blame] | 103 | #endif // __PUB_TOOL_LIBCPRINT_H |
| 104 | |
| 105 | /*--------------------------------------------------------------------*/ |
| 106 | /*--- end ---*/ |
| 107 | /*--------------------------------------------------------------------*/ |