BDE 4.14.0 Production release
Loading...
Searching...
No Matches
balst_resolverimpl_windows.h
Go to the documentation of this file.
1/// @file balst_resolverimpl_windows.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// balst_resolverimpl_windows.h -*-C++-*-
8#ifndef INCLUDED_BALST_RESOLVERIMPL_WINDOWS
9#define INCLUDED_BALST_RESOLVERIMPL_WINDOWS
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup balst_resolverimpl_windows balst_resolverimpl_windows
15/// @brief Provide resolution of symbols in stack trace for Windows objects.
16/// @addtogroup bal
17/// @{
18/// @addtogroup balst
19/// @{
20/// @addtogroup balst_resolverimpl_windows
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#balst_resolverimpl_windows-purpose"> Purpose</a>
25/// * <a href="#balst_resolverimpl_windows-classes"> Classes </a>
26/// * <a href="#balst_resolverimpl_windows-description"> Description </a>
27/// * <a href="#balst_resolverimpl_windows-usage"> Usage </a>
28///
29/// # Purpose {#balst_resolverimpl_windows-purpose}
30/// Provide resolution of symbols in stack trace for Windows objects.
31///
32/// # Classes {#balst_resolverimpl_windows-classes}
33///
34/// - balst::ResolverImpl<Windows>: symbol resolution for Windows objs
35///
36/// @see
37///
38/// # Description {#balst_resolverimpl_windows-description}
39/// This class provides a class this able to take a vector of
40/// `balst::StackTraceFrame`s that have only their `address` fields set, and
41/// sets as many of the other fields in the stack trace frames as possible. Elf
42/// objects are used on Solaris and Linux platforms.
43///
44/// ## Usage {#balst_resolverimpl_windows-usage}
45///
46///
47/// This component is an implementation detail of `balst` and is *not* intended
48/// for direct client use. It is subject to change without notice. As such, a
49/// usage example is not provided.
50/// @}
51/** @} */
52/** @} */
53
54/** @addtogroup bal
55 * @{
56 */
57/** @addtogroup balst
58 * @{
59 */
60/** @addtogroup balst_resolverimpl_windows
61 * @{
62 */
63
64#include <balscm_version.h>
65
67#include <balst_stacktrace.h>
69
70#include <bsl_vector.h>
71
72#include <bslma_allocator.h>
73
74
75
76#if defined(BALST_OBJECTFILEFORMAT_RESOLVER_WINDOWS)
77
78namespace balst {
79
80template <typename RESOLVER_POLICY>
81class ResolverImpl;
82
83 // =============================================
84 // class ResolverImpl<ObjectFileFormat::Windows>
85 // =============================================
86
87template <>
88class ResolverImpl<ObjectFileFormat::Windows> {
89 // This type is for resolving symbols in Windows executables. Resolving
90 // symbols on Windows is straightforward using the dbghelp.dll library,
91 // described at
92 // http://msdn.microsoft.com/en-us/library/ms681412(v=VS.85).aspx
93
94 private:
95 // NOT IMPLEMENTED
96 ResolverImpl();
97 ResolverImpl(const ResolverImpl&);
98 ResolverImpl& operator=(const ResolverImpl&);
99 ~ResolverImpl();
100
101 public:
102 // CLASS METHODS
103 static int resolve(StackTrace *stackTrace,
104 bool demangle);
105 // Given a specified stack trace object 'stackTrace' of stack trace
106 // frames with only their 'address' fields valid, set as many other
107 // fields of the frames as possible. The 'demangle' argument is
108 // ignored, demangling always happens on Windows. Return 0 if
109 // successful and a non-zero value otherwise.
110
111 static inline
112 int testFunc();
113 // For testing only. Do some random garbage and return a line number
114 // from within the routine.
115};
116
117 // ----------------------------
118 // class ResolverImpl
119 // ----------------------------
120
121inline
122int ResolverImpl<ObjectFileFormat::Windows>::testFunc()
123{
124 // Do some random garbage to generate some code, then return a line number
125 // within this routine
126
127 int line = 0, lineCopy = 0;
128
129 for (int ii = 0; true; ++ii) {
130 BSLS_ASSERT_OPT(line == lineCopy);
131
132 const int loopGuard = 0x8edf0000; // garbage with a lot of trailing
133 // 0's.
134 const int mask = 0xa72c3dca; // pure garbage
135
136 // k_LINE is not declared as enum as __LINE__ in some windows
137 // compilation modes cannot be evaluated as compile time constant.
138 // See DRQS 169040262 for details.
139 const int k_LINE = __LINE__;
140
141 for (int jj = 0; !(jj & loopGuard); ++jj) {
142 line ^= (jj & mask);
143 }
144
145 // The above loop will leave the value of 'line' unchanged.
146
147 BSLS_ASSERT_OPT(line == lineCopy);
148
149 if (line != 0) {
150 break;
151 }
152
153 line = k_LINE;
154 lineCopy = line;
155 }
156
157 return line;
158}
159
160} // close package namespace
161
162#endif
163
164
165
166#endif
167
168// ----------------------------------------------------------------------------
169// Copyright 2015 Bloomberg Finance L.P.
170//
171// Licensed under the Apache License, Version 2.0 (the "License");
172// you may not use this file except in compliance with the License.
173// You may obtain a copy of the License at
174//
175// http://www.apache.org/licenses/LICENSE-2.0
176//
177// Unless required by applicable law or agreed to in writing, software
178// distributed under the License is distributed on an "AS IS" BASIS,
179// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
180// See the License for the specific language governing permissions and
181// limitations under the License.
182// ----------------------------- END-OF-FILE ----------------------------------
183
184/** @} */
185/** @} */
186/** @} */
#define BSLS_ASSERT_OPT(X)
Definition bsls_assert.h:1856
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition balst_objectfileformat.h:161