Remote GDB: Turn on remote gdb in SE mode.
[gem5.git] / src / base / misc.hh
1 /*
2 * Copyright (c) 2002-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * Authors: Nathan Binkert
29 * Dave Greene
30 */
31
32 #ifndef __MISC_HH__
33 #define __MISC_HH__
34
35 #include <cassert>
36
37 #include "base/compiler.hh"
38 #include "base/cprintf.hh"
39 #include "base/varargs.hh"
40
41 #if defined(__SUNPRO_CC)
42 #define __FUNCTION__ "how to fix me?"
43 #endif
44
45 //
46 // This implements a cprintf based panic() function. panic() should
47 // be called when something happens that should never ever happen
48 // regardless of what the user does (i.e., an acutal m5 bug). panic()
49 // calls abort which can dump core or enter the debugger.
50 //
51 //
52 void __panic(const char *func, const char *file, int line, const char *format,
53 CPRINTF_DECLARATION) M5_ATTR_NORETURN;
54 void __panic(const char *func, const char *file, int line,
55 const std::string &format, CPRINTF_DECLARATION)
56 M5_ATTR_NORETURN;
57
58 inline void
59 __panic(const char *func, const char *file, int line,
60 const std::string &format, CPRINTF_DEFINITION)
61 {
62 __panic(func, file, line, format.c_str(), VARARGS_ALLARGS);
63 }
64 M5_PRAGMA_NORETURN(__panic)
65 #define panic(...) __panic(__FUNCTION__, __FILE__, __LINE__, __VA_ARGS__)
66
67 //
68 // This implements a cprintf based fatal() function. fatal() should
69 // be called when the simulation cannot continue due to some condition
70 // that is the user's fault (bad configuration, invalid arguments,
71 // etc.) and not a simulator bug. fatal() calls exit(1), i.e., a
72 // "normal" exit with an error code, as opposed to abort() like
73 // panic() does.
74 //
75 void __fatal(const char *func, const char *file, int line, const char *format,
76 CPRINTF_DECLARATION) M5_ATTR_NORETURN;
77 void __fatal(const char *func, const char *file, int line,
78 const std::string &format, CPRINTF_DECLARATION)
79 M5_ATTR_NORETURN;
80
81 inline void
82 __fatal(const char *func, const char *file, int line,
83 const std::string &format, CPRINTF_DEFINITION)
84 {
85 __fatal(func, file, line, format.c_str(), VARARGS_ALLARGS);
86 }
87 M5_PRAGMA_NORETURN(__fatal)
88 #define fatal(...) __fatal(__FUNCTION__, __FILE__, __LINE__, __VA_ARGS__)
89
90 //
91 // This implements a cprintf based warn
92 //
93 void __warn(const char *func, const char *file, int line, const char *format,
94 CPRINTF_DECLARATION);
95 inline void
96 __warn(const char *func, const char *file, int line, const std::string &format,
97 CPRINTF_DECLARATION)
98 {
99 __warn(func, file, line, format, VARARGS_ALLARGS);
100 }
101 #define warn(...) __warn(__FUNCTION__, __FILE__, __LINE__, __VA_ARGS__)
102
103 // Only print the warning message the first time it is seen. This
104 // doesn't check the warning string itself, it just only lets one
105 // warning come from the statement. So, even if the arguments change
106 // and that would have resulted in a different warning message,
107 // subsequent messages would still be supressed.
108 #define warn_once(...) do { \
109 static bool once = false; \
110 if (!once) { \
111 warn(__VA_ARGS__); \
112 once = true; \
113 } \
114 } while (0)
115
116 //
117 // assert() that prints out the current cycle
118 //
119 #define m5_assert(TEST) do { \
120 if (!(TEST)) \
121 ccprintf(std::cerr, "Assertion failure, curTick = %d\n", curTick); \
122 assert(TEST); \
123 } while (0)
124
125 #endif // __MISC_HH__