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 <stdint.h> 24 25 struct bcc_elf_usdt { 26 uint64_t pc; 27 uint64_t base_addr; 28 uint64_t semaphore; 29 30 const char *provider; 31 const char *name; 32 const char *arg_fmt; 33 }; 34 35 // Binary module path, bcc_elf_usdt struct, payload 36 typedef void (*bcc_elf_probecb)(const char *, const struct bcc_elf_usdt *, 37 void *); 38 // Symbol name, start address, length, payload 39 // Callback returning a negative value indicates to stop the iteration 40 typedef int (*bcc_elf_symcb)(const char *, uint64_t, uint64_t, void *); 41 // Segment virtual address, memory size, file offset, payload 42 // Callback returning a negative value indicates to stop the iteration 43 typedef int (*bcc_elf_load_sectioncb)(uint64_t, uint64_t, uint64_t, void *); 44 45 // Iterate over all USDT probes noted in a binary module 46 // Returns -1 on error, and 0 on success 47 int bcc_elf_foreach_usdt(const char *path, bcc_elf_probecb callback, 48 void *payload); 49 // Iterate over all executable load sections of an ELF 50 // Returns -1 on error, 1 if stopped by callback, and 0 on success 51 int bcc_elf_foreach_load_section(const char *path, 52 bcc_elf_load_sectioncb callback, 53 void *payload); 54 // Iterate over symbol table of a binary module 55 // Parameter "option" points to a bcc_symbol_option struct to indicate wheather 56 // and how to use debuginfo file, and what types of symbols to load. 57 // Returns -1 on error, and 0 on success or stopped by callback 58 int bcc_elf_foreach_sym(const char *path, bcc_elf_symcb callback, void *option, 59 void *payload); 60 // Iterate over all symbols from current system's vDSO 61 // Returns -1 on error, and 0 on success or stopped by callback 62 int bcc_elf_foreach_vdso_sym(bcc_elf_symcb callback, void *payload); 63 64 int bcc_elf_get_text_scn_info(const char *path, uint64_t *addr, 65 uint64_t *offset); 66 67 int bcc_elf_get_type(const char *path); 68 int bcc_elf_is_shared_obj(const char *path); 69 int bcc_elf_is_exe(const char *path); 70 int bcc_elf_is_vdso(const char *name); 71 72 #ifdef __cplusplus 73 } 74 #endif 75 #endif 76