• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2016 GitHub, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #ifndef LIBBCC_SYMS_H
17 #define LIBBCC_SYMS_H
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
23 #include <stdint.h>
24 
25 struct bcc_symbol {
26   const char *name;
27   const char *demangle_name;
28   const char *module;
29   uint64_t offset;
30 };
31 
32 typedef int (*SYM_CB)(const char *symname, uint64_t addr);
33 
34 #ifndef STT_GNU_IFUNC
35 #define STT_GNU_IFUNC 10
36 #endif
37 
38 #if defined(__powerpc64__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
39 // Indicate if the Local Entry Point (LEP) should be used as a symbol's
40 // start address
41 #define STT_PPC64LE_SYM_LEP 31
42 #endif
43 
44 static const uint32_t BCC_SYM_ALL_TYPES = 65535;
45 struct bcc_symbol_option {
46   int use_debug_file;
47   int check_debug_file_crc;
48   // Bitmask flags indicating what types of ELF symbols to use
49   uint32_t use_symbol_type;
50 };
51 
52 void *bcc_symcache_new(int pid, struct bcc_symbol_option *option);
53 void bcc_free_symcache(void *symcache, int pid);
54 
55 // The demangle_name pointer in bcc_symbol struct is returned from the
56 // __cxa_demangle function call, which is supposed to be freed by caller. Call
57 // this function after done using returned result of bcc_symcache_resolve.
58 void bcc_symbol_free_demangle_name(struct bcc_symbol *sym);
59 int bcc_symcache_resolve(void *symcache, uint64_t addr, struct bcc_symbol *sym);
60 int bcc_symcache_resolve_no_demangle(void *symcache, uint64_t addr,
61                                      struct bcc_symbol *sym);
62 
63 int bcc_symcache_resolve_name(void *resolver, const char *module,
64                               const char *name, uint64_t *addr);
65 void bcc_symcache_refresh(void *resolver);
66 
67 int bcc_resolve_global_addr(int pid, const char *module, const uint64_t address,
68                             uint64_t *global);
69 
70 // Call cb on every function symbol in the specified module. Uses simpler
71 // SYM_CB callback mainly for easier to use in Python API.
72 // Will prefer use debug file and check debug file CRC when reading the module.
73 int bcc_foreach_function_symbol(const char *module, SYM_CB cb);
74 
75 // Find the offset of a symbol in a module binary. If addr is not zero, will
76 // calculate the offset using the provided addr and the module's load address.
77 //
78 // If pid is provided, will use it to help lookup the module in the Process and
79 // enter the Process's mount Namespace.
80 //
81 // If option is not NULL, will respect the specified options for lookup.
82 // Otherwise default option will apply, which is to use debug file, verify
83 // checksum, and try all types of symbols.
84 //
85 // Return 0 on success and -1 on failure. Output will be write to sym. After
86 // use, sym->module need to be freed if it's not empty.
87 int bcc_resolve_symname(const char *module, const char *symname,
88                         const uint64_t addr, int pid,
89                         struct bcc_symbol_option* option,
90                         struct bcc_symbol *sym);
91 
92 #ifdef __cplusplus
93 }
94 #endif
95 #endif
96