|
|
/home/brennan/Software/sensix/tools/sim/platform.pc/dbg.hGo to the documentation of this file.00001 // $Id: dbg.h,v 1.1 2009/07/23 02:45:49 sean_m_brennan Exp $ 00002 00003 /* tab:4 00004 * "Copyright (c) 2000-2003 The Regents of the University of California. 00005 * All rights reserved. 00006 * 00007 * Permission to use, copy, modify, and distribute this software and its 00008 * documentation for any purpose, without fee, and without written agreement is 00009 * hereby granted, provided that the above copyright notice, the following 00010 * two paragraphs and the author appear in all copies of this software. 00011 * 00012 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR 00013 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT 00014 * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF 00015 * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00016 * 00017 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 00018 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 00019 * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS 00020 * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO 00021 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." 00022 * 00023 * Copyright (c) 2002-2003 Intel Corporation 00024 * All rights reserved. 00025 * 00026 * This file is distributed under the terms in the attached INTEL-LICENSE 00027 * file. If you do not find these files, copies can be found by writing to 00028 * Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA, 00029 * 94704. Attention: Intel License Inquiry. 00030 */ 00031 /* 00032 * 00033 * Authors: David Gay, Philip Levis (from work by Mike Castelle), Nelson Lee 00034 * Date last modified: 6/25/02 00035 * 00036 */ 00037 00038 /* 00039 * FILE: dbg.h 00040 * AUTHOR: pal 00041 * DESCR: Run-time configuration of debug output in FULLPC mode. 00042 * 00043 * Debug output determined by DBG environment variable. dbg_modes.h has 00044 * definitions of the settings possible. One can specify multiple debugging 00045 * outputs by comma-delimiting (e.g. DBG=sched,timer). Compiling with 00046 * NDEBUG defined (e.g. -DNDEBUG) will stop all of the debugging 00047 * output, will remove the debugging commands from the object file. 00048 * 00049 * example usage: dbg(DBG_TIMER, "timer went off at %d\n", time); 00050 * 00051 */ 00052 00060 #ifndef DBG_H 00061 #define DBG_H 00062 00063 #include "dbg_modes.h" 00064 /* We're in FULLPC mode, and debugging is not turned off */ 00065 #if defined(PLATFORM_PC) && !defined(NDEBUG) 00066 00067 #include <stdio.h> 00068 #include <stdarg.h> 00069 #include "nido.h" 00070 #include "GuiMsg.h" 00071 00072 typedef struct dbg_mode { 00073 char* d_name; 00074 unsigned long long d_mode; 00075 } TOS_dbg_mode_names; 00076 00077 TOS_dbg_mode dbg_modes = 0; 00078 norace bool dbg_suppress_stdout = 0; 00079 00080 static bool dbg_active(TOS_dbg_mode mode) 00081 { 00082 return (dbg_modes & mode) != 0; 00083 } 00084 00085 static void dbg_add_mode(const char *mode); 00086 static void dbg_add_modes(const char *modes); 00087 static void dbg_init(void); 00088 static void dbg_help(void); 00089 static void dbg_unset(); 00090 static void dbg_set(TOS_dbg_mode); 00091 00092 static void dbg(TOS_dbg_mode mode, const char *format, ...) 00093 { 00094 DebugMsgEvent ev; 00095 if (dbg_active(mode)) { 00096 va_list args; 00097 // XXX MDW - used to be printf 00098 if (!(mode & DBG_SIM)) { 00099 va_start(args, format); 00100 vsnprintf(ev.debugMessage, sizeof(ev.debugMessage), format, args); 00101 sendTossimEvent(NODE_NUM, AM_DEBUGMSGEVENT, tos_state.tos_time, &ev); 00102 va_end(args); 00103 } 00104 if (! dbg_suppress_stdout) { 00105 va_start(args, format); 00106 // XXX MDW - used to be vprintf 00107 fprintf(stdout, "%i: ", TOS_LOCAL_ADDRESS); 00108 vfprintf(stdout, format, args); 00109 va_end(args); 00110 } 00111 } 00112 } 00113 00114 static void dbg_clear(TOS_dbg_mode mode, const char *format, ...) 00115 { 00116 DebugMsgEvent ev; 00117 if (dbg_active(mode)) { 00118 va_list args; 00119 if (!(mode & DBG_SIM)) { 00120 va_start(args, format); 00121 vsnprintf(ev.debugMessage, sizeof(ev.debugMessage), format, args); 00122 sendTossimEvent(NODE_NUM, AM_DEBUGMSGEVENT, tos_state.tos_time, &ev); 00123 va_end(args); 00124 } 00125 if (! dbg_suppress_stdout) { 00126 va_start(args, format); 00127 // XXX MDW - used to be vprintf 00128 vfprintf(stdout, format, args); 00129 va_end(args); 00130 } 00131 } 00132 } 00133 00134 #else 00135 /* No debugging */ 00136 00137 #define dbg(...) { } 00138 #define dbg_clear(...) { } 00139 #define dbg_add_mode(...) { } 00140 #define dbg_add_modes(...) { } 00141 #define dbg_init() { } 00142 #define dbg_help() { } 00143 #define dbg_active(x) (FALSE) 00144 00145 //static inline void dbg(TOS_dbg_mode mode, const char *format, ...) { } 00146 //static inline void dbg_clear(TOS_dbg_mode mode, const char *format, ...) { } 00147 //static inline bool dbg_active(TOS_dbg_mode mode) { return FALSE; } 00148 //static inline void dbg_add_mode(const char *mode) { } 00149 //static inline void dbg_add_modes(const char *modes) { } 00150 //static inline void dbg_init(void) { } 00151 //static inline void dbg_help(void) { } 00152 #endif 00153 00154 #endif /* DBG_H */ |