sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1 | |
| 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 | |
| 37 | static char vg_mbuf[M_VG_MSGBUF]; |
| 38 | static int vg_n_mbuf; |
| 39 | |
| 40 | static 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 | |
| 50 | void |
| 51 | VG_(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. */ |
| 60 | void 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 | |
| 70 | void 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 | |
| 86 | void 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 | |
| 95 | void VG_(startup_logging) ( void ) |
| 96 | { |
| 97 | } |
| 98 | |
| 99 | void VG_(shutdown_logging) ( void ) |
| 100 | { |
| 101 | } |
| 102 | |
| 103 | /*--------------------------------------------------------------------*/ |
| 104 | /*--- end vg_message.c ---*/ |
| 105 | /*--------------------------------------------------------------------*/ |