aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llcommon/llerror.h
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:44:46 -0500
committerJacek Antonelli2008-08-15 23:44:46 -0500
commit38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch)
treeadca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/llcommon/llerror.h
parentREADME.txt (diff)
downloadmeta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz
Second Life viewer sources 1.13.2.12
Diffstat (limited to '')
-rw-r--r--linden/indra/llcommon/llerror.h237
1 files changed, 237 insertions, 0 deletions
diff --git a/linden/indra/llcommon/llerror.h b/linden/indra/llcommon/llerror.h
new file mode 100644
index 0000000..04e8eee
--- /dev/null
+++ b/linden/indra/llcommon/llerror.h
@@ -0,0 +1,237 @@
1/**
2 * @file llerror.h
3 * @brief Constants, functions, and macros for logging and runtime errors.
4 *
5 * Copyright (c) 2001-2007, Linden Research, Inc.
6 *
7 * The source code in this file ("Source Code") is provided by Linden Lab
8 * to you under the terms of the GNU General Public License, version 2.0
9 * ("GPL"), unless you have obtained a separate licensing agreement
10 * ("Other License"), formally executed by you and Linden Lab. Terms of
11 * the GPL can be found in doc/GPL-license.txt in this distribution, or
12 * online at http://secondlife.com/developers/opensource/gplv2
13 *
14 * There are special exceptions to the terms and conditions of the GPL as
15 * it is applied to this Source Code. View the full text of the exception
16 * in the file doc/FLOSS-exception.txt in this software distribution, or
17 * online at http://secondlife.com/developers/opensource/flossexception
18 *
19 * By copying, modifying or distributing this software, you acknowledge
20 * that you have read and understood your obligations described above,
21 * and agree to abide by those obligations.
22 *
23 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
24 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
25 * COMPLETENESS OR PERFORMANCE.
26 */
27
28#ifndef LL_LLERROR_H
29#define LL_LLERROR_H
30
31#include <sstream>
32#include <stdio.h>
33#include <stdarg.h>
34
35#include "llerrorstream.h"
36#include "llerrorbuffer.h"
37
38// Specific error codes
39const S32 LL_ERR_NOERR = 0;
40const S32 LL_ERR_ASSET_REQUEST_FAILED = -1;
41//const S32 LL_ERR_ASSET_REQUEST_INVALID = -2;
42const S32 LL_ERR_ASSET_REQUEST_NONEXISTENT_FILE = -3;
43const S32 LL_ERR_ASSET_REQUEST_NOT_IN_DATABASE = -4;
44const S32 LL_ERR_INSUFFICIENT_PERMISSIONS = -5;
45const S32 LL_ERR_EOF = -39;
46const S32 LL_ERR_CANNOT_OPEN_FILE = -42;
47const S32 LL_ERR_FILE_NOT_FOUND = -43;
48const S32 LL_ERR_FILE_EMPTY = -44;
49const S32 LL_ERR_TCP_TIMEOUT = -23016;
50const S32 LL_ERR_CIRCUIT_GONE = -23017;
51
52// Error types
53
54#define LLERR_IMAGE (1 << 1) // Image requests
55#define LLERR_MESSAGE (1 << 2) // Messaging
56#define LLERR_PERF (1 << 3) // Performance
57#define LLERR_SQL (1 << 4) // SQL statements
58#define LLERR_DOUG (1 << 5) // Doug's debugging
59#define LLERR_USER_INPUT (1 << 6) // Keyboard and mouse
60#define LLERR_TIMING (1 << 7) // Verbose time info
61#define LLERR_TASK (1 << 8) // Tracking tasks
62#define LLERR_MSG_HANDLER (1 << 9) //
63#define LLERR_CIRCUIT_INFO (1 << 10) // Message system circuit info
64#define LLERR_PHYSICS (1 << 11) // physics
65#define LLERR_VFS (1 << 12) // VFS
66const U32 LLERR_ALL = 0xffff;
67const U32 LLERR_NONE = 0x0;
68
69// Define one of these for different error levels in release...
70// #define RELEASE_SHOW_DEBUG // Define this if you want your release builds to show lldebug output.
71#define RELEASE_SHOW_INFO // Define this if you want your release builds to show llinfo output
72#define RELEASE_SHOW_WARN // Define this if you want your release builds to show llwarn output.
73
74
75//////////////////////////////////////////
76//
77// Implementation - ignore
78//
79//
80#ifdef _DEBUG
81#define SHOW_DEBUG
82#define SHOW_WARN
83#define SHOW_INFO
84#define SHOW_ASSERT
85#else // _DEBUG
86
87#ifdef RELEASE_SHOW_DEBUG
88#define SHOW_DEBUG
89#endif
90
91#ifdef RELEASE_SHOW_WARN
92#define SHOW_WARN
93#endif
94
95#ifdef RELEASE_SHOW_INFO
96#define SHOW_INFO
97#endif
98
99#ifdef RELEASE_SHOW_ASSERT
100#define SHOW_ASSERT
101#endif
102
103#endif // _DEBUG
104
105
106extern LLErrorStream gErrorStream;
107
108
109// LL Error macros
110//
111// Usage:
112//
113// llerrs << "An error, oh my!" << variable << endl;
114// llwarns << "Another error, fuck me!" << variable << endl;
115// llwarnst(LLERR_IMAGE) << "Debug, mother fucker" << endl;
116//
117// NOTE: The output format of filename(lineno): is so that MS DevStudio
118// can parse the output and automatically jump to that location
119
120inline std::string llerrno_string(int errnum)
121{
122 std::stringstream res;
123 res << "error(" << errnum << "):" << strerror(errnum) << " ";
124 return res.str();
125}
126
127inline std::string llerror_file_line(const char* file, S32 line)
128{
129 std::stringstream res;
130 res << file << "(" <<line << ")";
131 return res.str();
132}
133
134// Used to throw an error which is always causes a system halt.
135#define llerrs if (gErrorStream.isEnabledFor(LLErrorBuffer::FATAL)) \
136 { std::ostringstream llerror_oss; LLErrorBuffer::ELevel llerror_level = LLErrorBuffer::FATAL; \
137 llerror_oss << llerror_file_line(__FILE__, __LINE__) << " : error\n"; \
138 llerror_oss << "ERROR: " << llerror_file_line(__FILE__, __LINE__) << " "
139
140// Used to show warnings
141#define llwarns if (gErrorStream.isEnabledFor(LLErrorBuffer::WARN)) \
142 { std::ostringstream llerror_oss; LLErrorBuffer::ELevel llerror_level = LLErrorBuffer::WARN; \
143 if (gErrorStream.getPrintLocation()) llerror_oss << llerror_file_line(__FILE__, __LINE__) << " : WARNING: "; \
144 else llerror_oss << "WARNING: "; \
145 llerror_oss
146
147// Alerts are for serious non-fatal situations that are not supposed to happen and need to alert someone
148#define llalerts if (gErrorStream.isEnabledFor(LLErrorBuffer::WARN)) \
149 { std::ostringstream llerror_oss; LLErrorBuffer::ELevel llerror_level = LLErrorBuffer::WARN; \
150 if (gErrorStream.getPrintLocation()) llerror_oss << llerror_file_line(__FILE__, __LINE__) << " : ALERT: "; \
151 else llerror_oss << "ALERT: "; \
152 llerror_oss
153
154// Used to show informational messages that don't get disabled
155#define llinfos if (gErrorStream.isEnabledFor(LLErrorBuffer::INFO)) \
156 { std::ostringstream llerror_oss; LLErrorBuffer::ELevel llerror_level = LLErrorBuffer::INFO; \
157 if (gErrorStream.getPrintLocation()) llerror_oss << llerror_file_line(__FILE__, __LINE__) << " : INFO: "; \
158 else llerror_oss << "INFO: "; \
159 llerror_oss
160
161#define llinfost(type) if (gErrorStream.isEnabledFor(LLErrorBuffer::INFO, type)) \
162 { std::ostringstream llerror_oss; LLErrorBuffer::ELevel llerror_level = LLErrorBuffer::INFO; \
163 if (gErrorStream.getPrintLocation()) llerror_oss << llerror_file_line(__FILE__, __LINE__) << " : INFO: "; \
164 else llerror_oss << "INFO: [" << #type << "] "; \
165 llerror_oss
166
167// Used for general debugging output
168#define lldebugs if (gErrorStream.isEnabledFor(LLErrorBuffer::DEBUG)) \
169 { std::ostringstream llerror_oss; LLErrorBuffer::ELevel llerror_level = LLErrorBuffer::DEBUG; \
170 if (gErrorStream.getPrintLocation()) llerror_oss << llerror_file_line(__FILE__, __LINE__) << " : DEBUG: "; \
171 else llerror_oss << "DEBUG: "; \
172 llerror_oss
173
174#define lldebugst(type) if (gErrorStream.isEnabledFor(LLErrorBuffer::DEBUG, type)) \
175 { std::ostringstream llerror_oss; LLErrorBuffer::ELevel llerror_level = LLErrorBuffer::DEBUG; \
176 if (gErrorStream.getPrintLocation()) llerror_oss << llerror_file_line(__FILE__, __LINE__) << " : DEBUG: "; \
177 else llerror_oss << "DEBUG: [" << #type << "] "; \
178 llerror_oss
179
180#define llendl std::endl; gErrorStream.crashOnError(llerror_oss, llerror_level); }
181#define llendflush std::endl << std::flush; gErrorStream.crashOnError(llerror_oss, llerror_level); }
182#define llcont llerror_oss
183
184#define llerror(msg, num) llerrs << "Error # " << num << ": " << msg << llendl;
185
186#define llwarning(msg, num) llwarns << "Warning # " << num << ": " << msg << llendl;
187
188#ifdef SHOW_ASSERT
189#define llassert(func) if (!(func)) llerrs << "ASSERT (" << #func << ")" << llendl;
190#else
191#define llassert(func)
192#endif
193#define llassert_always(func) if (!(func)) llerrs << "ASSERT (" << #func << ")" << llendl;
194
195#ifdef SHOW_ASSERT
196#define llverify(func) if (!(func)) llerrs << "ASSERT (" << #func << ")" << llendl;
197#else
198#define llverify(func) (func); // get rid of warning C4189
199#endif
200
201// handy compile-time assert - enforce those template parameters!
202#define cassert(expn) typedef char __C_ASSERT__[(expn)?1:-1]
203
204// Makes the app go down in flames, but on purpose!
205void _llcrash_and_loop();
206
207// Use as follows:
208// llinfos << llformat("Test:%d (%.2f %.2f)", idx, x, y) << llendl;
209//
210// *NOTE: buffer limited to 1024, (but vsnprintf prevents overrun)
211// should perhaps be replaced with boost::format.
212inline std::string llformat(const char *fmt, ...)
213{
214 char tstr[1024]; /* Flawfinder: ignore */
215 va_list va;
216 va_start(va, fmt);
217#if LL_WINDOWS
218 _vsnprintf(tstr, 1024, fmt, va);
219#else
220 vsnprintf(tstr, 1024, fmt, va); /* Flawfinder: ignore */
221#endif
222 va_end(va);
223 return std::string(tstr);
224}
225
226// Helper class to temporarily change error level for the current scope.
227class LLScopedErrorLevel
228{
229public:
230 LLScopedErrorLevel(LLErrorBuffer::ELevel error_level);
231 ~LLScopedErrorLevel();
232
233private:
234 LLErrorBuffer::ELevel mOrigErrorLevel;
235};
236
237#endif // LL_LLERROR_H