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 | 0f157dd | 2013-10-18 14:27:36 +0000 | [diff] [blame] | 10 | Copyright (C) 2000-2013 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 | |
florian | 535fb1b | 2013-09-15 13:54:34 +0000 | [diff] [blame] | 34 | #include "pub_tool_basics.h" // VG_ macro |
| 35 | |
njn | 36a20fa | 2005-06-03 03:08:39 +0000 | [diff] [blame] | 36 | /* --------------------------------------------------------------------- |
njn | b1cc5d6 | 2010-07-06 04:05:23 +0000 | [diff] [blame] | 37 | Formatting functions |
njn | 36a20fa | 2005-06-03 03:08:39 +0000 | [diff] [blame] | 38 | ------------------------------------------------------------------ */ |
| 39 | |
philippe | 6d0e77b | 2014-05-07 22:03:59 +0000 | [diff] [blame] | 40 | /* The formatting functions supports a subset (and 2 extensions) of |
| 41 | the 'printf' format. |
| 42 | The extensions are: |
| 43 | %pS : print a string (like %s) but escaping chars for XML safety. |
| 44 | %ps : with --xml=no, synonym for %s, with --xml=yes, synonym of %pS. |
| 45 | |
| 46 | Note: these extensions do not cause the compiler to barf with PRINTF_CHECK |
| 47 | as for the classical printf, %p requires a pointer, which must also |
| 48 | be provided for the %ps and %pS extensions. The s/S following %p |
| 49 | are understood by PRINTF_CHECK as characters to output. |
| 50 | */ |
| 51 | |
florian | dbb3584 | 2012-10-27 18:39:11 +0000 | [diff] [blame] | 52 | extern UInt VG_(sprintf) ( HChar* buf, const HChar* format, ... ) |
sewardj | 5d9dc75 | 2009-07-15 14:52:18 +0000 | [diff] [blame] | 53 | PRINTF_CHECK(2, 3); |
| 54 | |
florian | dbb3584 | 2012-10-27 18:39:11 +0000 | [diff] [blame] | 55 | extern UInt VG_(vsprintf) ( HChar* buf, const HChar* format, va_list vargs ) |
sewardj | 5d9dc75 | 2009-07-15 14:52:18 +0000 | [diff] [blame] | 56 | PRINTF_CHECK(2, 0); |
| 57 | |
florian | dbb3584 | 2012-10-27 18:39:11 +0000 | [diff] [blame] | 58 | extern UInt VG_(snprintf) ( HChar* buf, Int size, |
sewardj | 5d9dc75 | 2009-07-15 14:52:18 +0000 | [diff] [blame] | 59 | const HChar *format, ... ) |
| 60 | PRINTF_CHECK(3, 4); |
| 61 | |
florian | dbb3584 | 2012-10-27 18:39:11 +0000 | [diff] [blame] | 62 | extern UInt VG_(vsnprintf)( HChar* buf, Int size, |
sewardj | 5d9dc75 | 2009-07-15 14:52:18 +0000 | [diff] [blame] | 63 | const HChar *format, va_list vargs ) |
| 64 | PRINTF_CHECK(3, 0); |
| 65 | |
njn | b1cc5d6 | 2010-07-06 04:05:23 +0000 | [diff] [blame] | 66 | /* --------------------------------------------------------------------- |
| 67 | Output-printing functions |
| 68 | ------------------------------------------------------------------ */ |
| 69 | |
| 70 | // Note that almost all output goes to the file descriptor given by the |
| 71 | // --log-fd/--log-file/--log-socket argument, which defaults to 2 (stderr). |
| 72 | // (Except that some text always goes to stdout/stderr at startup, and |
| 73 | // debugging messages always go to stderr.) Hence no need for |
| 74 | // VG_(fprintf)(). |
| 75 | |
| 76 | /* No, really. I _am_ that strange. */ |
| 77 | #define OINK(nnn) VG_(message)(Vg_DebugMsg, "OINK %d\n",nnn) |
| 78 | |
| 79 | /* Print a message with a prefix that depends on the VgMsgKind. |
| 80 | Should be used for all user output. */ |
| 81 | |
| 82 | typedef |
| 83 | enum { // Prefix |
| 84 | Vg_FailMsg, // "valgrind:" |
| 85 | Vg_UserMsg, // "==pid==" |
| 86 | Vg_DebugMsg, // "--pid--" |
njn | b1cc5d6 | 2010-07-06 04:05:23 +0000 | [diff] [blame] | 87 | Vg_ClientMsg // "**pid**" |
| 88 | } |
| 89 | VgMsgKind; |
| 90 | |
| 91 | // These print output that isn't prefixed with anything, and should be |
| 92 | // used in very few cases, such as printing usage messages. |
| 93 | extern UInt VG_(printf) ( const HChar *format, ... ) |
| 94 | PRINTF_CHECK(1, 2); |
| 95 | extern UInt VG_(vprintf) ( const HChar *format, va_list vargs ) |
| 96 | PRINTF_CHECK(1, 0); |
| 97 | |
sewardj | 5d9dc75 | 2009-07-15 14:52:18 +0000 | [diff] [blame] | 98 | extern UInt VG_(printf_xml) ( const HChar *format, ... ) |
| 99 | PRINTF_CHECK(1, 2); |
| 100 | |
| 101 | extern UInt VG_(vprintf_xml) ( const HChar *format, va_list vargs ) |
| 102 | PRINTF_CHECK(1, 0); |
| 103 | |
florian | 12d2eb5 | 2014-10-30 22:17:56 +0000 | [diff] [blame] | 104 | typedef struct _VgFile VgFile; |
| 105 | |
| 106 | extern VgFile *VG_(fopen) ( const HChar *name, Int flags, Int mode ); |
| 107 | extern void VG_(fclose) ( VgFile *fp ); |
| 108 | extern UInt VG_(fprintf) ( VgFile *fp, const HChar *format, ... ) |
| 109 | PRINTF_CHECK(2, 3); |
| 110 | extern UInt VG_(vfprintf) ( VgFile *fp, const HChar *format, va_list vargs ) |
| 111 | PRINTF_CHECK(2, 0); |
| 112 | |
philippe | 07c0852 | 2014-05-14 20:39:27 +0000 | [diff] [blame] | 113 | /* Do a printf-style operation on either the XML |
| 114 | or normal output channel |
| 115 | or gdb output channel, depending on the setting of VG_(clo_xml) |
| 116 | and the state of VG_(log_output_sink). */ |
| 117 | extern UInt VG_(emit) ( const HChar* format, ... ) PRINTF_CHECK(1, 2); |
| 118 | |
njn | b1cc5d6 | 2010-07-06 04:05:23 +0000 | [diff] [blame] | 119 | /* Yet another, totally general, version of vprintf, which hands all |
| 120 | output bytes to CHAR_SINK, passing it OPAQUE as the second arg. */ |
| 121 | extern void VG_(vcbprintf)( void(*char_sink)(HChar, void* opaque), |
| 122 | void* opaque, |
| 123 | const HChar* format, va_list vargs ); |
njn | 856c54e | 2005-06-26 18:43:40 +0000 | [diff] [blame] | 124 | |
bart | a0b6b2c | 2008-07-07 06:49:24 +0000 | [diff] [blame] | 125 | extern UInt VG_(message)( VgMsgKind kind, const HChar* format, ... ) |
njn | b1cc5d6 | 2010-07-06 04:05:23 +0000 | [diff] [blame] | 126 | PRINTF_CHECK(2, 3); |
njn | 36a20fa | 2005-06-03 03:08:39 +0000 | [diff] [blame] | 127 | |
bart | a0b6b2c | 2008-07-07 06:49:24 +0000 | [diff] [blame] | 128 | extern UInt VG_(vmessage)( VgMsgKind kind, const HChar* format, va_list vargs ) |
njn | b1cc5d6 | 2010-07-06 04:05:23 +0000 | [diff] [blame] | 129 | PRINTF_CHECK(2, 0); |
bart | a0b6b2c | 2008-07-07 06:49:24 +0000 | [diff] [blame] | 130 | |
njn | 6f74a7e | 2009-03-12 00:06:45 +0000 | [diff] [blame] | 131 | // Short-cuts for VG_(message)(). |
njn | b1cc5d6 | 2010-07-06 04:05:23 +0000 | [diff] [blame] | 132 | |
| 133 | // This is used for messages printed due to start-up failures that occur |
| 134 | // before the preamble is printed, eg. due a bad executable. |
| 135 | extern UInt VG_(fmsg)( const HChar* format, ... ) PRINTF_CHECK(1, 2); |
| 136 | |
| 137 | // This is used if an option was bad for some reason. Note: don't use it just |
| 138 | // because an option was unrecognised -- return 'False' from |
| 139 | // VG_(tdict).tool_process_cmd_line_option) to indicate that -- use it if eg. |
| 140 | // an option was given an inappropriate argument. This function prints an |
| 141 | // error message, then shuts down the entire system. |
| 142 | __attribute__((noreturn)) |
florian | bbd9a21 | 2012-10-14 00:16:28 +0000 | [diff] [blame] | 143 | extern void VG_(fmsg_bad_option) ( const HChar* opt, const HChar* format, ... ) |
njn | b1cc5d6 | 2010-07-06 04:05:23 +0000 | [diff] [blame] | 144 | PRINTF_CHECK(2, 3); |
| 145 | |
| 146 | // This is used for messages that are interesting to the user: info about |
| 147 | // their program (eg. preamble, tool error messages, postamble) or stuff they |
| 148 | // requested. |
sewardj | 5d9dc75 | 2009-07-15 14:52:18 +0000 | [diff] [blame] | 149 | extern UInt VG_(umsg)( const HChar* format, ... ) PRINTF_CHECK(1, 2); |
njn | b1cc5d6 | 2010-07-06 04:05:23 +0000 | [diff] [blame] | 150 | |
| 151 | // This is used for debugging messages that are only of use to developers. |
sewardj | 5d9dc75 | 2009-07-15 14:52:18 +0000 | [diff] [blame] | 152 | extern UInt VG_(dmsg)( const HChar* format, ... ) PRINTF_CHECK(1, 2); |
njn | b1cc5d6 | 2010-07-06 04:05:23 +0000 | [diff] [blame] | 153 | |
sewardj | 5d9dc75 | 2009-07-15 14:52:18 +0000 | [diff] [blame] | 154 | /* Flush any output cached by previous calls to VG_(message) et al. */ |
| 155 | extern void VG_(message_flush) ( void ); |
bart | a0b6b2c | 2008-07-07 06:49:24 +0000 | [diff] [blame] | 156 | |
philippe | 68c6293 | 2015-04-21 20:56:49 +0000 | [diff] [blame] | 157 | /* Return a textual representation of a SysRes value in a statically |
| 158 | allocated buffer. The buffer will be overwritten with the next |
| 159 | invocation. */ |
florian | 596b3fe | 2015-04-20 20:42:42 +0000 | [diff] [blame] | 160 | extern const HChar *VG_(sr_as_string) ( SysRes sr ); |
| 161 | |
njn | 36a20fa | 2005-06-03 03:08:39 +0000 | [diff] [blame] | 162 | #endif // __PUB_TOOL_LIBCPRINT_H |
| 163 | |
| 164 | /*--------------------------------------------------------------------*/ |
| 165 | /*--- end ---*/ |
| 166 | /*--------------------------------------------------------------------*/ |