1 | /* $Id: VBoxDbgLog.h 69498 2017-10-28 15:07:25Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Logging helper
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2011-2016 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * The contents of this file may alternatively be used under the terms
|
---|
18 | * of the Common Development and Distribution License Version 1.0
|
---|
19 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | * CDDL are applicable instead of those of the GPL.
|
---|
22 | *
|
---|
23 | * You may elect to license modified versions of this file under the
|
---|
24 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | */
|
---|
26 |
|
---|
27 | #ifndef ___VBoxDbgLog_h___
|
---|
28 | #define ___VBoxDbgLog_h___
|
---|
29 |
|
---|
30 | #ifndef VBOX_DBG_LOG_NAME
|
---|
31 | # error VBOX_DBG_LOG_NAME should be defined!
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | /* Uncomment to show file/line info in the log */
|
---|
35 | /*#define VBOX_DBG_LOG_SHOWLINEINFO*/
|
---|
36 |
|
---|
37 | #define VBOX_DBG_LOG_PREFIX_FMT VBOX_DBG_LOG_NAME"::"LOG_FN_FMT": "
|
---|
38 | #define VBOX_DBG_LOG_PREFIX_PARMS __PRETTY_FUNCTION__
|
---|
39 |
|
---|
40 | #ifdef VBOX_DBG_LOG_SHOWLINEINFO
|
---|
41 | # define VBOX_DBG_LOG_SUFFIX_FMT " (%s:%d)\n"
|
---|
42 | # define VBOX_DBG_LOG_SUFFIX_PARMS ,__FILE__, __LINE__
|
---|
43 | #else
|
---|
44 | # define VBOX_DBG_LOG_SUFFIX_FMT "\n"
|
---|
45 | # define VBOX_DBG_LOG_SUFFIX_PARMS
|
---|
46 | #endif
|
---|
47 |
|
---|
48 | #ifdef DEBUG_misha
|
---|
49 | # define BP_WARN() AssertFailed()
|
---|
50 | #else
|
---|
51 | # define BP_WARN() do { } while (0)
|
---|
52 | #endif
|
---|
53 |
|
---|
54 | #define _LOGMSG_EXACT(_logger, _a) \
|
---|
55 | do \
|
---|
56 | { \
|
---|
57 | _logger(_a); \
|
---|
58 | } while (0)
|
---|
59 |
|
---|
60 | #define _LOGMSG(_logger, _a) \
|
---|
61 | do \
|
---|
62 | { \
|
---|
63 | _logger((VBOX_DBG_LOG_PREFIX_FMT, VBOX_DBG_LOG_PREFIX_PARMS)); \
|
---|
64 | _logger(_a); \
|
---|
65 | _logger((VBOX_DBG_LOG_SUFFIX_FMT VBOX_DBG_LOG_SUFFIX_PARMS)); \
|
---|
66 | } while (0)
|
---|
67 |
|
---|
68 | /* we can not print paged strings to RT logger, do it this way */
|
---|
69 | #define _LOGMSG_STR(_logger, _a, _f) do {\
|
---|
70 | int _i = 0; \
|
---|
71 | _logger(("\"")); \
|
---|
72 | for (;(_a)[_i];++_i) { \
|
---|
73 | _logger(("%"_f, (_a)[_i])); \
|
---|
74 | }\
|
---|
75 | _logger(("\"\n")); \
|
---|
76 | } while (0)
|
---|
77 |
|
---|
78 | #define _LOGMSG_USTR(_logger, _a) do {\
|
---|
79 | int _i = 0; \
|
---|
80 | _logger(("\"")); \
|
---|
81 | for (;_i<(_a)->Length/2;++_i) { \
|
---|
82 | _logger(("%c", (_a)->Buffer[_i])); \
|
---|
83 | }\
|
---|
84 | _logger(("\"\n")); \
|
---|
85 | } while (0)
|
---|
86 |
|
---|
87 | #define WARN_NOBP(_a) \
|
---|
88 | do \
|
---|
89 | { \
|
---|
90 | Log((VBOX_DBG_LOG_PREFIX_FMT"WARNING! ", VBOX_DBG_LOG_PREFIX_PARMS)); \
|
---|
91 | Log(_a); \
|
---|
92 | Log((VBOX_DBG_LOG_SUFFIX_FMT VBOX_DBG_LOG_SUFFIX_PARMS)); \
|
---|
93 | } while (0)
|
---|
94 |
|
---|
95 | #define WARN(_a) \
|
---|
96 | do \
|
---|
97 | { \
|
---|
98 | WARN_NOBP(_a); \
|
---|
99 | BP_WARN(); \
|
---|
100 | } while (0)
|
---|
101 |
|
---|
102 | #define ASSERT_WARN(_a, _w) do {\
|
---|
103 | if(!(_a)) { \
|
---|
104 | WARN(_w); \
|
---|
105 | }\
|
---|
106 | } while (0)
|
---|
107 |
|
---|
108 | #define LOG(_a) _LOGMSG(Log, _a)
|
---|
109 | #define LOGREL(_a) _LOGMSG(LogRel, _a)
|
---|
110 | #define LOGF(_a) _LOGMSG(LogFlow, _a)
|
---|
111 | #define LOGF_ENTER() LOGF(("ENTER"))
|
---|
112 | #define LOGF_LEAVE() LOGF(("LEAVE"))
|
---|
113 | #define LOG_EXACT(_a) _LOGMSG_EXACT(Log, _a)
|
---|
114 | #define LOGREL_EXACT(_a) _LOGMSG_EXACT(LogRel, _a)
|
---|
115 | /* we can not print paged strings to RT logger, do it this way */
|
---|
116 | #define LOG_STRA(_a) do {\
|
---|
117 | _LOGMSG_STR(Log, _a, "c"); \
|
---|
118 | } while (0)
|
---|
119 | #define LOG_STRW(_a) do {\
|
---|
120 | _LOGMSG_STR(Log, _a, "c"); \
|
---|
121 | } while (0)
|
---|
122 | #define LOG_USTR(_a) do {\
|
---|
123 | _LOGMSG_USTR(Log, _a); \
|
---|
124 | } while (0)
|
---|
125 | #define LOGREL_STRA(_a) do {\
|
---|
126 | _LOGMSG_STR(LogRel, _a, "c"); \
|
---|
127 | } while (0)
|
---|
128 | #define LOGREL_STRW(_a) do {\
|
---|
129 | _LOGMSG_STR(LogRel, _a, "c"); \
|
---|
130 | } while (0)
|
---|
131 | #define LOGREL_USTR(_a) do {\
|
---|
132 | _LOGMSG_USTR(LogRel, _a); \
|
---|
133 | } while (0)
|
---|
134 |
|
---|
135 |
|
---|
136 | #endif
|
---|
137 |
|
---|