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_ELF_H 17 #define LIBBCC_ELF_H 18 19 #ifdef __cplusplus 20 extern "C" { 21 #endif 22 23 #include <stddef.h> 24 #include <stdint.h> 25 26 struct bcc_elf_usdt { 27 uint64_t pc; 28 uint64_t base_addr; 29 // Virtual address semaphore is found at 30 uint64_t semaphore; 31 32 const char *provider; 33 const char *name; 34 const char *arg_fmt; 35 36 // Offset from start of file where the semaphore is at 37 uint64_t semaphore_offset; 38 }; 39 40 // Binary module path, bcc_elf_usdt struct, payload 41 typedef void (*bcc_elf_probecb)(const char *, const struct bcc_elf_usdt *, 42 void *); 43 // Symbol name, start address, length, payload 44 // Callback returning a negative value indicates to stop the iteration 45 typedef int (*bcc_elf_symcb)(const char *, uint64_t, uint64_t, void *); 46 // Section idx, str table idx, str length, start address, length, payload 47 typedef int (*bcc_elf_symcb_lazy)(size_t, size_t, size_t, uint64_t, uint64_t, 48 int, void *); 49 // Segment virtual address, memory size, file offset, payload 50 // Callback returning a negative value indicates to stop the iteration 51 typedef int (*bcc_elf_load_sectioncb)(uint64_t, uint64_t, uint64_t, void *); 52 53 // Iterate over all USDT probes noted in a binary module 54 // Returns -1 on error, and 0 on success 55 int bcc_elf_foreach_usdt(const char *path, bcc_elf_probecb callback, 56 void *payload); 57 // Iterate over all executable load sections of an ELF 58 // Returns -1 on error, 1 if stopped by callback, and 0 on success 59 int bcc_elf_foreach_load_section(const char *path, 60 bcc_elf_load_sectioncb callback, 61 void *payload); 62 // Iterate over symbol table of a binary module 63 // Parameter "option" points to a bcc_symbol_option struct to indicate whether 64 // and how to use debuginfo file, and what types of symbols to load. 65 // Returns -1 on error, and 0 on success or stopped by callback 66 int bcc_elf_foreach_sym(const char *path, bcc_elf_symcb callback, void *option, 67 void *payload); 68 // Similar to bcc_elf_foreach_sym, but pass reference to symbolized string along 69 // with symbolized string length 70 int bcc_elf_foreach_sym_lazy(const char *path, bcc_elf_symcb_lazy callback, 71 void *option, void *payload); 72 // Iterate over all symbols from current system's vDSO 73 // Returns -1 on error, and 0 on success or stopped by callback 74 int bcc_elf_foreach_vdso_sym(bcc_elf_symcb callback, void *payload); 75 76 int bcc_elf_get_text_scn_info(const char *path, uint64_t *addr, 77 uint64_t *offset); 78 79 int bcc_elf_get_type(const char *path); 80 int bcc_elf_is_shared_obj(const char *path); 81 int bcc_elf_is_exe(const char *path); 82 int bcc_elf_is_vdso(const char *name); 83 int bcc_free_memory(); 84 int bcc_elf_get_buildid(const char *path, char *buildid); 85 int bcc_elf_symbol_str(const char *path, size_t section_idx, 86 size_t str_table_idx, char *out, size_t len, 87 int debugfile); 88 89 #ifdef __cplusplus 90 } 91 #endif 92 #endif 93