BDE 4.14.0 Production release
Loading...
Searching...
No Matches
balst_resolverimpl_dladdr.h
Go to the documentation of this file.
1/// @file balst_resolverimpl_dladdr.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// balst_resolverimpl_dladdr.h -*-C++-*-
8#ifndef INCLUDED_BALST_RESOLVERIMPL_DLADDR
9#define INCLUDED_BALST_RESOLVERIMPL_DLADDR
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup balst_resolverimpl_dladdr balst_resolverimpl_dladdr
15/// @brief Provide functions for resolving a stack trace using `dladdr`.
16/// @addtogroup bal
17/// @{
18/// @addtogroup balst
19/// @{
20/// @addtogroup balst_resolverimpl_dladdr
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#balst_resolverimpl_dladdr-purpose"> Purpose</a>
25/// * <a href="#balst_resolverimpl_dladdr-classes"> Classes </a>
26/// * <a href="#balst_resolverimpl_dladdr-description"> Description </a>
27/// * <a href="#balst_resolverimpl_dladdr-usage"> Usage </a>
28///
29/// # Purpose {#balst_resolverimpl_dladdr-purpose}
30/// Provide functions for resolving a stack trace using `dladdr`.
31///
32/// # Classes {#balst_resolverimpl_dladdr-classes}
33///
34/// - balst::ResolverImpl<Dladdr>: symbol resolution using `dladdr`
35///
36/// @see balst_resolverimpl_elf,
37/// balst_resolverimpl_windows,
38/// balst_resolverimpl_xcoff
39///
40/// # Description {#balst_resolverimpl_dladdr-description}
41/// This component provides a class,
42/// `balst::Resolver<Dladdr>`, that, given a vector of
43/// `balst::StackTraceFrame` objects that have only their `address` fields set,
44/// resolves some of the other fields in those frames. This resolver will work
45/// for any platform that supports the `dladdr` function (e.g., Darwin and
46/// Linux). Note that `dladdr` is not a standard system function, but
47/// documentation is frequently available via `man dladdr` on supported
48/// platforms such as Linux and Apple Mac OSX.
49///
50/// Note that this resolving implementation is currently used for the operating
51/// systems based on the Mach kernel, in particular Apple Mac OSX.
52///
53/// In addition to `dladdr`, this code uses the `abi::__cxa_demangle` function
54/// supplied by the gnu and clang compilers for demangling symbol names.
55/// Documentation can be found:
56/// * /usr/include/cxxabi.h
57/// * `http://gcc.gnu.org/onlinedocs/libstdc++/manual/ext_demangling.html`
58///
59/// ## Usage {#balst_resolverimpl_dladdr-usage}
60///
61///
62/// This component is an implementation detail of `balst` and is *not* intended
63/// for direct client use. It is subject to change without notice. As such, a
64/// usage example is not provided.
65/// @}
66/** @} */
67/** @} */
68
69/** @addtogroup bal
70 * @{
71 */
72/** @addtogroup balst
73 * @{
74 */
75/** @addtogroup balst_resolverimpl_dladdr
76 * @{
77 */
78
79#include <balscm_version.h>
80
82#include <balst_stacktrace.h>
84
85#include <bsls_types.h>
86
87#include <bsl_vector.h>
88
89
90
91#if defined(BALST_OBJECTFILEFORMAT_RESOLVER_DLADDR)
92
93
94namespace balst {
95
96template <typename RESOLVER_POLICY>
97class ResolverImpl;
98
99 // ============================================
100 // class ResolverImpl<ObjectFileFormat::Dladdr>
101 // ============================================
102
103template <>
104class ResolverImpl<ObjectFileFormat::Dladdr> {
105 // This class provides a public static 'resolve' method that, given a
106 // vector of 'StackTraceFrame' objects that have only their 'address'
107 // fields set, resolves all other fields in those frames.
108
109 // DATA
110 StackTrace *d_stackTrace_p; // pointer to stack trace object.
111 // The frames contained in this
112 // have their 'address' fields and
113 // nothing else initialized upon
114 // entry to 'resolve', which infers
115 // as many other fields of them as
116 // possible.
117
118 bool d_demangleFlag; // whether we demangle names
119
120 private:
121 // NOT IMPLEMENTED
122 ResolverImpl(const ResolverImpl&);
123 ResolverImpl& operator=(
124 const ResolverImpl&);
125
126 private:
127 // PRIVATE CREATORS
128 ResolverImpl(StackTrace *stackTrace,
129 bool demanglingPreferredFlag);
130 // Create an stack trace reolver that can populate other fields of the
131 // specified 'stackTrace' object given previously populated 'address'
132 // fields, and if the specified 'demanglingPreferredFlag' is 'true',
133 // attempt to demangle symbol names.
134
135 ~ResolverImpl();
136 // Destroy this object.
137
138 // PRIVATE MANIPULATORS
139 int resolveFrame(StackTraceFrame *frame);
140 // Given the specified 'frame' with all fields uninitializd other than
141 // the initialized 'address()' field, populate as many other fields as
142 // possible, currently the 'liberaryFileName()', 'mangledSymbolName()',
143 // 'offsetFromSymbol()', and 'symbolName()' fields. If
144 // 'd_demangleFlag' is true, 'symbolName()' will be a demangled form of
145 // 'mangledSymbolName()', otherwise the two fields will be identical.
146 // Return 0 on success and a non-zero value if any problems were
147 // encountered. Note that this function is defined as a member
148 // function to make use of the 'd_demanglingBuf_p' buffer, and avoid
149 // the use of a stack or heap allocated buffer for demangling symbols
150 // -- using additional stack or heap memory may cause problems when
151 // generating a stack trace to capture the state of a thread that has
152 // failed due to stack or heap corruption.
153
154 public:
155 // CLASS METHODS
156 static int resolve(StackTrace *stackTrace,
157 bool demanglingPreferredFlag);
158 // Populate information for the specified '*stackTrace', which contains
159 // a sequence of randomly-accessible stack trace frames. Specify
160 // 'demanglingPreferredFlag', to determine whether demangling is to
161 // occur. The behavior is undefined unless all the 'address' field in
162 // '*stackTrace' are valid and other fields are invalid.
163};
164
165} // close package namespace
166
167#endif
168
169
170
171#endif
172
173// ----------------------------------------------------------------------------
174// Copyright 2015 Bloomberg Finance L.P.
175//
176// Licensed under the Apache License, Version 2.0 (the "License");
177// you may not use this file except in compliance with the License.
178// You may obtain a copy of the License at
179//
180// http://www.apache.org/licenses/LICENSE-2.0
181//
182// Unless required by applicable law or agreed to in writing, software
183// distributed under the License is distributed on an "AS IS" BASIS,
184// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
185// See the License for the specific language governing permissions and
186// limitations under the License.
187// ----------------------------- END-OF-FILE ----------------------------------
188
189/** @} */
190/** @} */
191/** @} */
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition balst_objectfileformat.h:161