blob: 343a859628c0c1958c919288ca219b0f9d5328b4 [file] [log] [blame]
sewardjde4a1d02002-03-22 01:27:54 +00001
2/*--------------------------------------------------------------------*/
3/*--- For sending error/informative messages. ---*/
4/*--- vg_message.c ---*/
5/*--------------------------------------------------------------------*/
6
7/*
8 This file is part of Valgrind, an x86 protected-mode emulator
9 designed for debugging and profiling binaries on x86-Unixes.
10
11 Copyright (C) 2000-2002 Julian Seward
12 jseward@acm.org
13 Julian_Seward@muraroa.demon.co.uk
14
15 This program is free software; you can redistribute it and/or
16 modify it under the terms of the GNU General Public License as
17 published by the Free Software Foundation; either version 2 of the
18 License, or (at your option) any later version.
19
20 This program is distributed in the hope that it will be useful, but
21 WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 General Public License for more details.
24
25 You should have received a copy of the GNU General Public License
26 along with this program; if not, write to the Free Software
27 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
28 02111-1307, USA.
29
30 The GNU General Public License is contained in the file LICENSE.
31*/
32
33
34#include "vg_include.h"
35
36
37static char vg_mbuf[M_VG_MSGBUF];
38static int vg_n_mbuf;
39
40static void add_to_buf ( Char c )
41{
42 if (vg_n_mbuf >= (M_VG_MSGBUF-1)) return;
43 vg_mbuf[vg_n_mbuf++] = c;
44 vg_mbuf[vg_n_mbuf] = 0;
45}
46
47
48/* Publically visible from here onwards. */
49
50void
51VG_(add_to_msg) ( Char *format, ... )
52{
53 va_list vargs;
54 va_start(vargs,format);
55 VG_(vprintf) ( add_to_buf, format, vargs );
56 va_end(vargs);
57}
58
59/* Send a simple single-part message. */
60void VG_(message) ( VgMsgKind kind, Char* format, ... )
61{
62 va_list vargs;
63 va_start(vargs,format);
64 VG_(start_msg) ( kind );
65 VG_(vprintf) ( add_to_buf, format, vargs );
66 va_end(vargs);
67 VG_(end_msg)();
68}
69
70void VG_(start_msg) ( VgMsgKind kind )
71{
72 Char c;
73 vg_n_mbuf = 0;
74 vg_mbuf[vg_n_mbuf] = 0;
75 switch (kind) {
76 case Vg_UserMsg: c = '='; break;
77 case Vg_DebugMsg: c = '-'; break;
78 case Vg_DebugExtraMsg: c = '+'; break;
79 default: c = '?'; break;
80 }
81 VG_(add_to_msg)( "%c%c%d%c%c ",
82 c,c, VG_(getpid)(), c,c );
83}
84
85
86void VG_(end_msg) ( void )
87{
88 if (VG_(clo_logfile_fd) >= 0) {
89 add_to_buf('\n');
90 VG_(write)(VG_(clo_logfile_fd), vg_mbuf, VG_(strlen)(vg_mbuf));
91 }
92}
93
94
95void VG_(startup_logging) ( void )
96{
97}
98
99void VG_(shutdown_logging) ( void )
100{
101}
102
103/*--------------------------------------------------------------------*/
104/*--- end vg_message.c ---*/
105/*--------------------------------------------------------------------*/