dwarf_loader: Use libdw__lock for dwarf_getlocation(s)
[dwarves.git] / libctf.h
blob749be8955c52caeba38f4731fb91a4ddb2dac220
1 /*
2 SPDX-License-Identifier: GPL-2.0-only
4 Copyright (C) 2019 Arnaldo Carvalho de Melo <acme@redhat.com>
5 */
7 #ifndef _LIBCTF_H
8 #define _LIBCTF_H
10 #include <stdbool.h>
11 #include <stdint.h>
12 #include <stddef.h>
13 #include <elf.h>
15 #include "gobuffer.h"
16 #include "elf_symtab.h"
18 struct ctf {
19 void *buf;
20 void *priv;
21 Elf *elf;
22 struct elf_symtab *symtab;
23 GElf_Ehdr ehdr;
24 struct gobuffer objects; /* data/variables */
25 struct gobuffer types;
26 struct gobuffer funcs;
27 struct strings *strings;
28 char *filename;
29 size_t size;
30 int swapped;
31 int in_fd;
32 uint8_t wordsize;
33 uint32_t type_index;
36 struct ctf *ctf__new(const char *filename, Elf *elf);
37 void ctf__delete(struct ctf *ctf);
39 bool ctf__ignore_symtab_function(const GElf_Sym *sym, const char *sym_name);
40 bool ctf__ignore_symtab_object(const GElf_Sym *sym, const char *sym_name);
42 int ctf__load(struct ctf *ctf);
44 uint16_t ctf__get16(struct ctf *ctf, uint16_t *p);
45 uint32_t ctf__get32(struct ctf *ctf, uint32_t *p);
46 void ctf__put16(struct ctf *ctf, uint16_t *p, uint16_t val);
47 void ctf__put32(struct ctf *ctf, uint32_t *p, uint32_t val);
49 void *ctf__get_buffer(struct ctf *ctf);
50 size_t ctf__get_size(struct ctf *ctf);
52 int ctf__load_symtab(struct ctf *ctf);
54 uint32_t ctf__add_base_type(struct ctf *ctf, uint32_t name, uint16_t size);
55 uint32_t ctf__add_fwd_decl(struct ctf *ctf, uint32_t name);
56 uint32_t ctf__add_short_type(struct ctf *ctf, uint16_t kind, uint16_t type, uint32_t name);
57 void ctf__add_short_member(struct ctf *ctf, uint32_t name, uint16_t type,
58 uint16_t offset, int64_t *position);
59 void ctf__add_full_member(struct ctf *ctf, uint32_t name, uint16_t type,
60 uint64_t offset, int64_t *position);
61 uint32_t ctf__add_struct(struct ctf *ctf, uint16_t kind, uint32_t name,
62 uint64_t size, uint16_t nr_members, int64_t *position);
63 uint32_t ctf__add_array(struct ctf *ctf, uint16_t type, uint16_t index_type, uint32_t nelems);
64 void ctf__add_parameter(struct ctf *ctf, uint16_t type, int64_t *position);
65 uint32_t ctf__add_function_type(struct ctf *ctf, uint16_t type,
66 uint16_t nr_parms, bool varargs, int64_t *position);
67 uint32_t ctf__add_enumeration_type(struct ctf *ctf, uint32_t name, uint16_t size,
68 uint16_t nr_entries, int64_t *position);
69 void ctf__add_enumerator(struct ctf *ctf, uint32_t name, uint32_t value,
70 int64_t *position);
72 void ctf__add_function_parameter(struct ctf *ctf, uint16_t type,
73 int64_t *position);
74 int ctf__add_function(struct ctf *ctf, uint16_t type, uint16_t nr_parms,
75 bool varargs, int64_t *position);
77 int ctf__add_object(struct ctf *ctf, uint16_t type);
79 void ctf__set_strings(struct ctf *ctf, struct strings *strings);
80 int ctf__encode(struct ctf *ctf, uint8_t flags);
82 char *ctf__string(struct ctf *ctf, uint32_t ref);
84 /**
85 * ctf__for_each_symtab_function - iterate thru all the symtab functions
87 * @ctf: struct ctf instance to iterate
88 * @index: uint32_t index
89 * @sym: GElf_Sym iterator
91 #define ctf__for_each_symtab_function(ctf, index, sym) \
92 elf_symtab__for_each_symbol(ctf->symtab, index, sym) \
93 if (ctf__ignore_symtab_function(&sym, \
94 elf_sym__name(&sym, \
95 ctf->symtab))) \
96 continue; \
97 else
99 /**
100 * ctf__for_each_symtab_object - iterate thru all the symtab objects
102 * @ctf: struct ctf instance to iterate
103 * @index: uint32_t index
104 * @sym: GElf_Sym iterator
106 #define ctf__for_each_symtab_object(ctf, index, sym) \
107 elf_symtab__for_each_symbol(ctf->symtab, index, sym) \
108 if (ctf__ignore_symtab_object(&sym, \
109 elf_sym__name(&sym, \
110 ctf->symtab))) \
111 continue; \
112 else
115 #endif /* _LIBCTF_H */