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