bloaty/third_party/abseil-cpp/absl/debugging/internal/symbolize.h
Go to the documentation of this file.
1 // Copyright 2018 The Abseil Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 // This file contains internal parts of the Abseil symbolizer.
16 // Do not depend on the anything in this file, it may change at anytime.
17 
18 #ifndef ABSL_DEBUGGING_INTERNAL_SYMBOLIZE_H_
19 #define ABSL_DEBUGGING_INTERNAL_SYMBOLIZE_H_
20 
21 #ifdef __cplusplus
22 
23 #include <cstddef>
24 #include <cstdint>
25 
26 #include "absl/base/config.h"
27 #include "absl/strings/string_view.h"
28 
29 #ifdef ABSL_INTERNAL_HAVE_ELF_SYMBOLIZE
30 #error ABSL_INTERNAL_HAVE_ELF_SYMBOLIZE cannot be directly set
31 #elif defined(__ELF__) && defined(__GLIBC__) && !defined(__native_client__) && \
32  !defined(__asmjs__) && !defined(__wasm__)
33 #define ABSL_INTERNAL_HAVE_ELF_SYMBOLIZE 1
34 
35 #include <elf.h>
36 #include <link.h> // For ElfW() macro.
37 #include <functional>
38 #include <string>
39 
40 namespace absl {
42 namespace debugging_internal {
43 
44 // Iterates over all sections, invoking callback on each with the section name
45 // and the section header.
46 //
47 // Returns true on success; otherwise returns false in case of errors.
48 //
49 // This is not async-signal-safe.
50 bool ForEachSection(int fd,
52  const ElfW(Shdr) &)>& callback);
53 
54 // Gets the section header for the given name, if it exists. Returns true on
55 // success. Otherwise, returns false.
56 bool GetSectionHeaderByName(int fd, const char *name, size_t name_len,
57  ElfW(Shdr) *out);
58 
59 } // namespace debugging_internal
61 } // namespace absl
62 
63 #endif // ABSL_INTERNAL_HAVE_ELF_SYMBOLIZE
64 
65 #ifdef ABSL_INTERNAL_HAVE_DARWIN_SYMBOLIZE
66 #error ABSL_INTERNAL_HAVE_DARWIN_SYMBOLIZE cannot be directly set
67 #elif defined(__APPLE__)
68 #define ABSL_INTERNAL_HAVE_DARWIN_SYMBOLIZE 1
69 #endif
70 
71 namespace absl {
73 namespace debugging_internal {
74 
75 struct SymbolDecoratorArgs {
76  // The program counter we are getting symbolic name for.
77  const void *pc;
78  // 0 for main executable, load address for shared libraries.
79  ptrdiff_t relocation;
80  // Read-only file descriptor for ELF image covering "pc",
81  // or -1 if no such ELF image exists in /proc/self/maps.
82  int fd;
83  // Output buffer, size.
84  // Note: the buffer may not be empty -- default symbolizer may have already
85  // produced some output, and earlier decorators may have adorned it in
86  // some way. You are free to replace or augment the contents (within the
87  // symbol_buf_size limit).
88  char *const symbol_buf;
89  size_t symbol_buf_size;
90  // Temporary scratch space, size.
91  // Use that space in preference to allocating your own stack buffer to
92  // conserve stack.
93  char *const tmp_buf;
94  size_t tmp_buf_size;
95  // User-provided argument
96  void* arg;
97 };
98 using SymbolDecorator = void (*)(const SymbolDecoratorArgs *);
99 
100 // Installs a function-pointer as a decorator. Returns a value less than zero
101 // if the system cannot install the decorator. Otherwise, returns a unique
102 // identifier corresponding to the decorator. This identifier can be used to
103 // uninstall the decorator - See RemoveSymbolDecorator() below.
104 int InstallSymbolDecorator(SymbolDecorator decorator, void* arg);
105 
106 // Removes a previously installed function-pointer decorator. Parameter "ticket"
107 // is the return-value from calling InstallSymbolDecorator().
108 bool RemoveSymbolDecorator(int ticket);
109 
110 // Remove all installed decorators. Returns true if successful, false if
111 // symbolization is currently in progress.
112 bool RemoveAllSymbolDecorators(void);
113 
114 // Registers an address range to a file mapping.
115 //
116 // Preconditions:
117 // start <= end
118 // filename != nullptr
119 //
120 // Returns true if the file was successfully registered.
121 bool RegisterFileMappingHint(const void* start, const void* end,
122  uint64_t offset, const char* filename);
123 
124 // Looks up the file mapping registered by RegisterFileMappingHint for an
125 // address range. If there is one, the file name is stored in *filename and
126 // *start and *end are modified to reflect the registered mapping. Returns
127 // whether any hint was found.
128 bool GetFileMappingHint(const void** start, const void** end, uint64_t* offset,
129  const char** filename);
130 
131 } // namespace debugging_internal
133 } // namespace absl
134 
135 #endif // __cplusplus
136 
137 #include <stdbool.h>
138 
139 #ifdef __cplusplus
140 extern "C"
141 #endif // __cplusplus
142 
143  bool
144  AbslInternalGetFileMappingHint(const void** start, const void** end,
145  uint64_t* offset, const char** filename);
146 
147 #endif // ABSL_DEBUGGING_INTERNAL_SYMBOLIZE_H_
filename
const char * filename
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:135
absl::string_view
Definition: abseil-cpp/absl/strings/string_view.h:167
setup.name
name
Definition: setup.py:542
ABSL_NAMESPACE_END
#define ABSL_NAMESPACE_END
Definition: third_party/abseil-cpp/absl/base/config.h:171
start
static uint64_t start
Definition: benchmark-pound.c:74
ABSL_NAMESPACE_BEGIN
#define ABSL_NAMESPACE_BEGIN
Definition: third_party/abseil-cpp/absl/base/config.h:170
end
char * end
Definition: abseil-cpp/absl/strings/internal/str_format/float_conversion.cc:1008
bloaty::pe::ForEachSection
void ForEachSection(const PeFile &pe, Func &&section_func)
Definition: pe.cc:184
elf.h
uint64_t
unsigned __int64 uint64_t
Definition: stdint-msvc2008.h:90
arg
Definition: cmdline.cc:40
callback
static void callback(void *arg, int status, int timeouts, struct hostent *host)
Definition: acountry.c:224
arg
struct arg arg
absl
Definition: abseil-cpp/absl/algorithm/algorithm.h:31
absl::out
char * out
Definition: abseil-cpp/absl/synchronization/mutex.h:1048
function
std::function< bool(GrpcTool *, int, const char **, const CliCredentials &, GrpcToolOutputCallback)> function
Definition: grpc_tool.cc:250
AbslInternalGetFileMappingHint
bool AbslInternalGetFileMappingHint(const void **start, const void **end, uint64_t *offset, const char **filename)
offset
voidpf uLong offset
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:142


grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:24