blob: 8536a815b4cd621d044ff461402b0090cae25f8c [file] [log] [blame]
njn36a20fa2005-06-03 03:08:39 +00001
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
sewardj03f8d3f2012-08-05 15:46:46 +000010 Copyright (C) 2000-2012 Julian Seward
njn36a20fa2005-06-03 03:08:39 +000011 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/* ---------------------------------------------------------------------
njnb1cc5d62010-07-06 04:05:23 +000035 Formatting functions
njn36a20fa2005-06-03 03:08:39 +000036 ------------------------------------------------------------------ */
37
floriandbb35842012-10-27 18:39:11 +000038extern UInt VG_(sprintf) ( HChar* buf, const HChar* format, ... )
sewardj5d9dc752009-07-15 14:52:18 +000039 PRINTF_CHECK(2, 3);
40
floriandbb35842012-10-27 18:39:11 +000041extern UInt VG_(vsprintf) ( HChar* buf, const HChar* format, va_list vargs )
sewardj5d9dc752009-07-15 14:52:18 +000042 PRINTF_CHECK(2, 0);
43
floriandbb35842012-10-27 18:39:11 +000044extern UInt VG_(snprintf) ( HChar* buf, Int size,
sewardj5d9dc752009-07-15 14:52:18 +000045 const HChar *format, ... )
46 PRINTF_CHECK(3, 4);
47
floriandbb35842012-10-27 18:39:11 +000048extern UInt VG_(vsnprintf)( HChar* buf, Int size,
sewardj5d9dc752009-07-15 14:52:18 +000049 const HChar *format, va_list vargs )
50 PRINTF_CHECK(3, 0);
51
njnb1cc5d62010-07-06 04:05:23 +000052// Percentify n/m with d decimal places. Includes the '%' symbol at the end.
53// Right justifies in 'buf'.
floriandbb35842012-10-27 18:39:11 +000054extern void VG_(percentify)(ULong n, ULong m, UInt d, Int n_buf, HChar buf[]);
sewardj5d9dc752009-07-15 14:52:18 +000055
njnb1cc5d62010-07-06 04:05:23 +000056
57/* ---------------------------------------------------------------------
58 Output-printing functions
59 ------------------------------------------------------------------ */
60
61// Note that almost all output goes to the file descriptor given by the
62// --log-fd/--log-file/--log-socket argument, which defaults to 2 (stderr).
63// (Except that some text always goes to stdout/stderr at startup, and
64// debugging messages always go to stderr.) Hence no need for
65// VG_(fprintf)().
66
67/* No, really. I _am_ that strange. */
68#define OINK(nnn) VG_(message)(Vg_DebugMsg, "OINK %d\n",nnn)
69
70/* Print a message with a prefix that depends on the VgMsgKind.
71 Should be used for all user output. */
72
73typedef
74 enum { // Prefix
75 Vg_FailMsg, // "valgrind:"
76 Vg_UserMsg, // "==pid=="
77 Vg_DebugMsg, // "--pid--"
njnb1cc5d62010-07-06 04:05:23 +000078 Vg_ClientMsg // "**pid**"
79 }
80 VgMsgKind;
81
82// These print output that isn't prefixed with anything, and should be
83// used in very few cases, such as printing usage messages.
84extern UInt VG_(printf) ( const HChar *format, ... )
85 PRINTF_CHECK(1, 2);
86extern UInt VG_(vprintf) ( const HChar *format, va_list vargs )
87 PRINTF_CHECK(1, 0);
88
sewardj5d9dc752009-07-15 14:52:18 +000089extern UInt VG_(printf_xml) ( const HChar *format, ... )
90 PRINTF_CHECK(1, 2);
91
92extern UInt VG_(vprintf_xml) ( const HChar *format, va_list vargs )
93 PRINTF_CHECK(1, 0);
94
njnb1cc5d62010-07-06 04:05:23 +000095/* Yet another, totally general, version of vprintf, which hands all
96 output bytes to CHAR_SINK, passing it OPAQUE as the second arg. */
97extern void VG_(vcbprintf)( void(*char_sink)(HChar, void* opaque),
98 void* opaque,
99 const HChar* format, va_list vargs );
njn856c54e2005-06-26 18:43:40 +0000100
barta0b6b2c2008-07-07 06:49:24 +0000101extern UInt VG_(message)( VgMsgKind kind, const HChar* format, ... )
njnb1cc5d62010-07-06 04:05:23 +0000102 PRINTF_CHECK(2, 3);
njn36a20fa2005-06-03 03:08:39 +0000103
barta0b6b2c2008-07-07 06:49:24 +0000104extern UInt VG_(vmessage)( VgMsgKind kind, const HChar* format, va_list vargs )
njnb1cc5d62010-07-06 04:05:23 +0000105 PRINTF_CHECK(2, 0);
barta0b6b2c2008-07-07 06:49:24 +0000106
njn6f74a7e2009-03-12 00:06:45 +0000107// Short-cuts for VG_(message)().
njnb1cc5d62010-07-06 04:05:23 +0000108
109// This is used for messages printed due to start-up failures that occur
110// before the preamble is printed, eg. due a bad executable.
111extern UInt VG_(fmsg)( const HChar* format, ... ) PRINTF_CHECK(1, 2);
112
113// This is used if an option was bad for some reason. Note: don't use it just
114// because an option was unrecognised -- return 'False' from
115// VG_(tdict).tool_process_cmd_line_option) to indicate that -- use it if eg.
116// an option was given an inappropriate argument. This function prints an
117// error message, then shuts down the entire system.
118__attribute__((noreturn))
florianbbd9a212012-10-14 00:16:28 +0000119extern void VG_(fmsg_bad_option) ( const HChar* opt, const HChar* format, ... )
njnb1cc5d62010-07-06 04:05:23 +0000120 PRINTF_CHECK(2, 3);
121
122// This is used for messages that are interesting to the user: info about
123// their program (eg. preamble, tool error messages, postamble) or stuff they
124// requested.
sewardj5d9dc752009-07-15 14:52:18 +0000125extern UInt VG_(umsg)( const HChar* format, ... ) PRINTF_CHECK(1, 2);
njnb1cc5d62010-07-06 04:05:23 +0000126
127// This is used for debugging messages that are only of use to developers.
sewardj5d9dc752009-07-15 14:52:18 +0000128extern UInt VG_(dmsg)( const HChar* format, ... ) PRINTF_CHECK(1, 2);
njnb1cc5d62010-07-06 04:05:23 +0000129
sewardj5d9dc752009-07-15 14:52:18 +0000130/* Flush any output cached by previous calls to VG_(message) et al. */
131extern void VG_(message_flush) ( void );
barta0b6b2c2008-07-07 06:49:24 +0000132
njn36a20fa2005-06-03 03:08:39 +0000133#endif // __PUB_TOOL_LIBCPRINT_H
134
135/*--------------------------------------------------------------------*/
136/*--- end ---*/
137/*--------------------------------------------------------------------*/