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 #include "linux/bpf.h" 25 #include "bcc_proc.h" 26 27 struct bcc_symbol { 28 const char *name; 29 const char *demangle_name; 30 const char *module; 31 uint64_t offset; 32 }; 33 34 typedef int (*SYM_CB)(const char *symname, uint64_t addr); 35 struct mod_info; 36 37 #ifndef STT_GNU_IFUNC 38 #define STT_GNU_IFUNC 10 39 #endif 40 41 #if defined(__powerpc64__) && defined(_CALL_ELF) && _CALL_ELF == 2 42 // Indicate if the Local Entry Point (LEP) should be used as a symbol's 43 // start address 44 #define STT_PPC64_ELFV2_SYM_LEP 31 45 #endif 46 47 static const uint32_t BCC_SYM_ALL_TYPES = 65535; 48 struct bcc_symbol_option { 49 int use_debug_file; 50 int check_debug_file_crc; 51 // Symbolize on-demand or symbolize everything ahead of time 52 int lazy_symbolize; 53 // Bitmask flags indicating what types of ELF symbols to use 54 uint32_t use_symbol_type; 55 }; 56 57 void *bcc_symcache_new(int pid, struct bcc_symbol_option *option); 58 void bcc_free_symcache(void *symcache, int pid); 59 60 // The demangle_name pointer in bcc_symbol struct is returned from the 61 // __cxa_demangle function call, which is supposed to be freed by caller. Call 62 // this function after done using returned result of bcc_symcache_resolve. 63 void bcc_symbol_free_demangle_name(struct bcc_symbol *sym); 64 int bcc_symcache_resolve(void *symcache, uint64_t addr, struct bcc_symbol *sym); 65 int bcc_symcache_resolve_no_demangle(void *symcache, uint64_t addr, 66 struct bcc_symbol *sym); 67 68 int bcc_symcache_resolve_name(void *resolver, const char *module, 69 const char *name, uint64_t *addr); 70 void bcc_symcache_refresh(void *resolver); 71 72 int _bcc_syms_find_module(struct mod_info *info, int enter_ns, void *p); 73 int bcc_resolve_global_addr(int pid, const char *module, const uint64_t address, 74 uint8_t inode_match_only, uint64_t *global); 75 76 /*bcc APIs for build_id stackmap support*/ 77 void *bcc_buildsymcache_new(void); 78 void bcc_free_buildsymcache(void *symcache); 79 int bcc_buildsymcache_add_module(void *resolver, const char *module_name); 80 int bcc_buildsymcache_resolve(void *resolver, 81 struct bpf_stack_build_id *trace, 82 struct bcc_symbol *sym); 83 // Call cb on every function symbol in the specified module. Uses simpler 84 // SYM_CB callback mainly for easier to use in Python API. 85 // Will prefer use debug file and check debug file CRC when reading the module. 86 int bcc_foreach_function_symbol(const char *module, SYM_CB cb); 87 88 // Find the offset of a symbol in a module binary. If addr is not zero, will 89 // calculate the offset using the provided addr and the module's load address. 90 // 91 // If pid is provided, will use it to help lookup the module in the Process and 92 // enter the Process's mount Namespace. 93 // 94 // If option is not NULL, will respect the specified options for lookup. 95 // Otherwise default option will apply, which is to use debug file, verify 96 // checksum, and try all types of symbols. 97 // 98 // Return 0 on success and -1 on failure. Output will be write to sym. After 99 // use, sym->module need to be freed if it's not empty. 100 int bcc_resolve_symname(const char *module, const char *symname, 101 const uint64_t addr, int pid, 102 struct bcc_symbol_option* option, 103 struct bcc_symbol *sym); 104 105 #ifdef __cplusplus 106 } 107 #endif 108 #endif 109