• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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-2010 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 /* ---------------------------------------------------------------------
35    Formatting functions
36    ------------------------------------------------------------------ */
37 
38 extern UInt VG_(sprintf)  ( Char* buf, const HChar* format, ... )
39                           PRINTF_CHECK(2, 3);
40 
41 extern UInt VG_(vsprintf) ( Char* buf, const HChar* format, va_list vargs )
42                           PRINTF_CHECK(2, 0);
43 
44 extern UInt VG_(snprintf) ( Char* buf, Int size,
45                                        const HChar *format, ... )
46                           PRINTF_CHECK(3, 4);
47 
48 extern UInt VG_(vsnprintf)( Char* buf, Int size,
49                                        const HChar *format, va_list vargs )
50                           PRINTF_CHECK(3, 0);
51 
52 // Percentify n/m with d decimal places.  Includes the '%' symbol at the end.
53 // Right justifies in 'buf'.
54 extern void VG_(percentify)(ULong n, ULong m, UInt d, Int n_buf, char buf[]);
55 
56 
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 
73 typedef
74    enum {                 // Prefix
75       Vg_FailMsg,         // "valgrind:"
76       Vg_UserMsg,         // "==pid=="
77       Vg_DebugMsg,        // "--pid--"
78       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.
84 extern UInt VG_(printf)   ( const HChar *format, ... )
85                           PRINTF_CHECK(1, 2);
86 extern UInt VG_(vprintf)  ( const HChar *format, va_list vargs )
87                           PRINTF_CHECK(1, 0);
88 
89 // The "_no_f_c" functions here are just like their non-"_no_f_c" counterparts
90 // but without the PRINTF_CHECK, so they can be used with our non-standard %t
91 // format specifier.
92 
93 // These are the same as the non "_xml" versions above, except the
94 // output goes on the selected XML output channel instead of the
95 // normal one.
96 extern UInt VG_(printf_xml)  ( const HChar *format, ... )
97                              PRINTF_CHECK(1, 2);
98 
99 extern UInt VG_(vprintf_xml) ( const HChar *format, va_list vargs )
100                              PRINTF_CHECK(1, 0);
101 
102 extern UInt VG_(printf_xml_no_f_c) ( const HChar *format, ... );
103 
104 /* Yet another, totally general, version of vprintf, which hands all
105    output bytes to CHAR_SINK, passing it OPAQUE as the second arg. */
106 extern void VG_(vcbprintf)( void(*char_sink)(HChar, void* opaque),
107                             void* opaque,
108                             const HChar* format, va_list vargs );
109 
110 extern UInt VG_(message_no_f_c)( VgMsgKind kind, const HChar* format, ... );
111 extern UInt VG_(message)( VgMsgKind kind, const HChar* format, ... )
112    PRINTF_CHECK(2, 3);
113 
114 extern UInt VG_(vmessage)( VgMsgKind kind, const HChar* format, va_list vargs )
115    PRINTF_CHECK(2, 0);
116 
117 // Short-cuts for VG_(message)().
118 
119 // This is used for messages printed due to start-up failures that occur
120 // before the preamble is printed, eg. due a bad executable.
121 extern UInt VG_(fmsg)( const HChar* format, ... ) PRINTF_CHECK(1, 2);
122 
123 // This is used if an option was bad for some reason.  Note: don't use it just
124 // because an option was unrecognised -- return 'False' from
125 // VG_(tdict).tool_process_cmd_line_option) to indicate that -- use it if eg.
126 // an option was given an inappropriate argument.  This function prints an
127 // error message, then shuts down the entire system.
128 __attribute__((noreturn))
129 extern void VG_(fmsg_bad_option) ( HChar* opt, const HChar* format, ... )
130    PRINTF_CHECK(2, 3);
131 
132 // This is used for messages that are interesting to the user:  info about
133 // their program (eg. preamble, tool error messages, postamble) or stuff they
134 // requested.
135 extern UInt VG_(umsg)( const HChar* format, ... ) PRINTF_CHECK(1, 2);
136 
137 // This is used for debugging messages that are only of use to developers.
138 extern UInt VG_(dmsg)( const HChar* format, ... ) PRINTF_CHECK(1, 2);
139 
140 /* Flush any output cached by previous calls to VG_(message) et al. */
141 extern void VG_(message_flush) ( void );
142 
143 #endif   // __PUB_TOOL_LIBCPRINT_H
144 
145 /*--------------------------------------------------------------------*/
146 /*--- end                                                          ---*/
147 /*--------------------------------------------------------------------*/
148