2 /*--------------------------------------------------------------------*/
3 /*--- Printing libc stuff. pub_tool_libcprint.h ---*/
4 /*--------------------------------------------------------------------*/
7 This file is part of Valgrind, a dynamic binary instrumentation
10 Copyright (C) 2000-2017 Julian Seward
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.
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.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, see <http://www.gnu.org/licenses/>.
26 The GNU General Public License is contained in the file COPYING.
29 #ifndef __PUB_TOOL_LIBCPRINT_H
30 #define __PUB_TOOL_LIBCPRINT_H
32 #include "pub_tool_basics.h" // VG_ macro
34 /* ---------------------------------------------------------------------
36 ------------------------------------------------------------------ */
38 /* The formatting functions supports a subset (and 2 extensions) of
41 %pS : print a string (like %s) but escaping chars for XML safety.
42 %ps : with --xml=no, synonym for %s, with --xml=yes, synonym of %pS.
44 Note: these extensions do not cause the compiler to barf with PRINTF_CHECK
45 as for the classical printf, %p requires a pointer, which must also
46 be provided for the %ps and %pS extensions. The s/S following %p
47 are understood by PRINTF_CHECK as characters to output.
50 extern UInt
VG_(sprintf
) ( HChar
* buf
, const HChar
* format
, ... )
53 extern UInt
VG_(vsprintf
) ( HChar
* buf
, const HChar
* format
, va_list vargs
)
56 extern UInt
VG_(snprintf
) ( HChar
* buf
, Int size
,
57 const HChar
*format
, ... )
60 extern UInt
VG_(vsnprintf
)( HChar
* buf
, Int size
,
61 const HChar
*format
, va_list vargs
)
64 /* ---------------------------------------------------------------------
65 Output-printing functions
66 ------------------------------------------------------------------ */
68 // Note that almost all output goes to the file descriptor given by the
69 // --log-fd/--log-file/--log-socket argument, which defaults to 2 (stderr).
70 // (Except that some text always goes to stdout/stderr at startup, and
71 // debugging messages always go to stderr.) Hence no need for
74 /* No, really. I _am_ that strange. */
75 #define OINK(nnn) VG_(message)(Vg_DebugMsg, "OINK %d\n",nnn)
77 /* Print a message with a prefix that depends on the VgMsgKind.
78 Should be used for all user output. */
82 Vg_FailMsg
, // "valgrind:"
83 Vg_UserMsg
, // "==pid=="
84 Vg_DebugMsg
, // "--pid--"
85 Vg_ClientMsg
// "**pid**"
89 // These print output that isn't prefixed with anything, and should be
90 // used in very few cases, such as printing usage messages.
91 extern UInt
VG_(printf
) ( const HChar
*format
, ... )
93 extern UInt
VG_(vprintf
) ( const HChar
*format
, va_list vargs
)
96 extern UInt
VG_(printf_xml
) ( const HChar
*format
, ... )
99 extern UInt
VG_(vprintf_xml
) ( const HChar
*format
, va_list vargs
)
102 typedef struct _VgFile VgFile
;
104 extern VgFile
*VG_(fopen
) ( const HChar
*name
, Int flags
, Int mode
);
105 extern void VG_(fclose
) ( VgFile
*fp
);
106 extern UInt
VG_(fprintf
) ( VgFile
*fp
, const HChar
*format
, ... )
108 extern UInt
VG_(vfprintf
) ( VgFile
*fp
, const HChar
*format
, va_list vargs
)
111 /* Do a printf-style operation on either the XML
112 or normal output channel
113 or gdb output channel, depending on the setting of VG_(clo_xml)
114 and the state of VG_(log_output_sink). */
115 extern UInt
VG_(emit
) ( const HChar
* format
, ... ) PRINTF_CHECK(1, 2);
117 /* Yet another, totally general, version of vprintf, which hands all
118 output bytes to CHAR_SINK, passing it OPAQUE as the second arg. */
119 extern void VG_(vcbprintf
)( void(*char_sink
)(HChar
, void* opaque
),
121 const HChar
* format
, va_list vargs
);
123 extern UInt
VG_(message
)( VgMsgKind kind
, const HChar
* format
, ... )
126 extern UInt
VG_(vmessage
)( VgMsgKind kind
, const HChar
* format
, va_list vargs
)
129 // Short-cuts for VG_(message)().
131 // This is used for messages printed due to start-up failures that occur
132 // before the preamble is printed, eg. due a bad executable.
133 extern UInt
VG_(fmsg
)( const HChar
* format
, ... ) PRINTF_CHECK(1, 2);
135 // This is used if an option was bad for some reason. Note: don't use it just
136 // because an option was unrecognised -- return 'False' from
137 // VG_(tdict).tool_process_cmd_line_option) to indicate that -- use it if eg.
138 // an option was given an inappropriate argument. This function prints an
139 // error message. It shuts down the entire system if the current parsing mode
141 extern void VG_(fmsg_bad_option
) ( const HChar
* opt
, const HChar
* format
, ... )
144 // This is used for messages that are interesting to the user: info about
145 // their program (eg. preamble, tool error messages, postamble) or stuff they
147 extern UInt
VG_(umsg
)( const HChar
* format
, ... ) PRINTF_CHECK(1, 2);
149 // This is used for debugging messages that are only of use to developers.
150 extern UInt
VG_(dmsg
)( const HChar
* format
, ... ) PRINTF_CHECK(1, 2);
152 /* Flush any output cached by previous calls to VG_(message) et al. */
153 extern void VG_(message_flush
) ( void );
155 /* Return a textual representation of a SysRes value in a statically
156 allocated buffer. The buffer will be overwritten with the next
158 extern const HChar
*VG_(sr_as_string
) ( SysRes sr
);
160 #endif // __PUB_TOOL_LIBCPRINT_H
162 /*--------------------------------------------------------------------*/
164 /*--------------------------------------------------------------------*/