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 10 Copyright (C) 2000-2013 Julian Seward 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 34 #include "pub_tool_basics.h" // VG_ macro 35 36 /* --------------------------------------------------------------------- 37 Formatting functions 38 ------------------------------------------------------------------ */ 39 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 52 extern UInt VG_(sprintf) ( HChar* buf, const HChar* format, ... ) 53 PRINTF_CHECK(2, 3); 54 55 extern UInt VG_(vsprintf) ( HChar* buf, const HChar* format, va_list vargs ) 56 PRINTF_CHECK(2, 0); 57 58 extern UInt VG_(snprintf) ( HChar* buf, Int size, 59 const HChar *format, ... ) 60 PRINTF_CHECK(3, 4); 61 62 extern UInt VG_(vsnprintf)( HChar* buf, Int size, 63 const HChar *format, va_list vargs ) 64 PRINTF_CHECK(3, 0); 65 66 // Percentify n/m with d decimal places. Includes the '%' symbol at the end. 67 // Right justifies in 'buf'. 68 extern void VG_(percentify)(ULong n, ULong m, UInt d, Int n_buf, HChar buf[]); 69 70 71 /* --------------------------------------------------------------------- 72 Output-printing functions 73 ------------------------------------------------------------------ */ 74 75 // Note that almost all output goes to the file descriptor given by the 76 // --log-fd/--log-file/--log-socket argument, which defaults to 2 (stderr). 77 // (Except that some text always goes to stdout/stderr at startup, and 78 // debugging messages always go to stderr.) Hence no need for 79 // VG_(fprintf)(). 80 81 /* No, really. I _am_ that strange. */ 82 #define OINK(nnn) VG_(message)(Vg_DebugMsg, "OINK %d\n",nnn) 83 84 /* Print a message with a prefix that depends on the VgMsgKind. 85 Should be used for all user output. */ 86 87 typedef 88 enum { // Prefix 89 Vg_FailMsg, // "valgrind:" 90 Vg_UserMsg, // "==pid==" 91 Vg_DebugMsg, // "--pid--" 92 Vg_ClientMsg // "**pid**" 93 } 94 VgMsgKind; 95 96 // These print output that isn't prefixed with anything, and should be 97 // used in very few cases, such as printing usage messages. 98 extern UInt VG_(printf) ( const HChar *format, ... ) 99 PRINTF_CHECK(1, 2); 100 extern UInt VG_(vprintf) ( const HChar *format, va_list vargs ) 101 PRINTF_CHECK(1, 0); 102 103 extern UInt VG_(printf_xml) ( const HChar *format, ... ) 104 PRINTF_CHECK(1, 2); 105 106 extern UInt VG_(vprintf_xml) ( const HChar *format, va_list vargs ) 107 PRINTF_CHECK(1, 0); 108 109 /* Do a printf-style operation on either the XML 110 or normal output channel 111 or gdb output channel, depending on the setting of VG_(clo_xml) 112 and the state of VG_(log_output_sink). */ 113 extern UInt VG_(emit) ( const HChar* format, ... ) PRINTF_CHECK(1, 2); 114 115 /* Yet another, totally general, version of vprintf, which hands all 116 output bytes to CHAR_SINK, passing it OPAQUE as the second arg. */ 117 extern void VG_(vcbprintf)( void(*char_sink)(HChar, void* opaque), 118 void* opaque, 119 const HChar* format, va_list vargs ); 120 121 extern UInt VG_(message)( VgMsgKind kind, const HChar* format, ... ) 122 PRINTF_CHECK(2, 3); 123 124 extern UInt VG_(vmessage)( VgMsgKind kind, const HChar* format, va_list vargs ) 125 PRINTF_CHECK(2, 0); 126 127 // Short-cuts for VG_(message)(). 128 129 // This is used for messages printed due to start-up failures that occur 130 // before the preamble is printed, eg. due a bad executable. 131 extern UInt VG_(fmsg)( const HChar* format, ... ) PRINTF_CHECK(1, 2); 132 133 // This is used if an option was bad for some reason. Note: don't use it just 134 // because an option was unrecognised -- return 'False' from 135 // VG_(tdict).tool_process_cmd_line_option) to indicate that -- use it if eg. 136 // an option was given an inappropriate argument. This function prints an 137 // error message, then shuts down the entire system. 138 __attribute__((noreturn)) 139 extern void VG_(fmsg_bad_option) ( const HChar* opt, const HChar* format, ... ) 140 PRINTF_CHECK(2, 3); 141 142 // This is used for messages that are interesting to the user: info about 143 // their program (eg. preamble, tool error messages, postamble) or stuff they 144 // requested. 145 extern UInt VG_(umsg)( const HChar* format, ... ) PRINTF_CHECK(1, 2); 146 147 // This is used for debugging messages that are only of use to developers. 148 extern UInt VG_(dmsg)( const HChar* format, ... ) PRINTF_CHECK(1, 2); 149 150 /* Flush any output cached by previous calls to VG_(message) et al. */ 151 extern void VG_(message_flush) ( void ); 152 153 #endif // __PUB_TOOL_LIBCPRINT_H 154 155 /*--------------------------------------------------------------------*/ 156 /*--- end ---*/ 157 /*--------------------------------------------------------------------*/ 158