LIEF: Library to Instrument Executable Formats Version 2.0.0
Loading...
Searching...
No Matches
DWARF/editor/Function.hpp
Go to the documentation of this file.
1/* Copyright 2022 - 2026 R. Thomas
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15#ifndef LIEF_DWARF_EDITOR_FUNCTION_H
16#define LIEF_DWARF_EDITOR_FUNCTION_H
17#include <cstdint>
18#include <memory>
19#include <string>
20#include <vector>
21
23#include "LIEF/visibility.h"
24
25
26namespace LIEF::dwarf::editor {
27class Type;
28class Variable;
29
30namespace details {
31class Function;
32class FunctionParameter;
33class FunctionLexicalBlock;
34class FunctionLabel;
35}
36
39 public:
41 range_t() = default;
42 range_t(uint64_t start, uint64_t end) :
43 start(start),
44 end(end) {}
45 uint64_t start = 0;
46 uint64_t end = 0;
47 };
48
52 public:
53 Parameter() = delete;
54 Parameter(std::unique_ptr<details::FunctionParameter> impl);
55
57
59 Parameter& assign_register(const std::string& name) LIEF_LIFETIMEBOUND;
60
63
64 private:
65 std::unique_ptr<details::FunctionParameter> impl_;
66 };
67
70 public:
71 LexicalBlock() = delete;
72 LexicalBlock(std::unique_ptr<details::FunctionLexicalBlock> impl);
73
75 std::unique_ptr<LexicalBlock> add_block(uint64_t start,
76 uint64_t end) LIEF_LIFETIMEBOUND;
77
79 std::unique_ptr<LexicalBlock>
80 add_block(const std::vector<range_t>& range) LIEF_LIFETIMEBOUND;
81
85 add_description(const std::string& description) LIEF_LIFETIMEBOUND;
86
88 LexicalBlock& add_name(const std::string& name) LIEF_LIFETIMEBOUND;
89
91
92 private:
93 std::unique_ptr<details::FunctionLexicalBlock> impl_;
94 };
95
98 public:
99 Label() = delete;
100 Label(std::unique_ptr<details::FunctionLabel> impl);
101
103
104 private:
105 std::unique_ptr<details::FunctionLabel> impl_;
106 };
107
108 Function() = delete;
109 Function(std::unique_ptr<details::Function> impl);
110
113
118 Function& set_low_high(uint64_t low, uint64_t high) LIEF_LIFETIMEBOUND;
119
124 Function& set_ranges(const std::vector<range_t>& ranges) LIEF_LIFETIMEBOUND;
125
130
133
135 std::unique_ptr<Parameter> add_parameter(const std::string& name,
136 const Type& type) LIEF_LIFETIMEBOUND;
137
139 std::unique_ptr<Variable>
141
143 std::unique_ptr<LexicalBlock> add_lexical_block(uint64_t start,
144 uint64_t end) LIEF_LIFETIMEBOUND;
145
147 std::unique_ptr<Label> add_label(uint64_t addr,
148 const std::string& label) LIEF_LIFETIMEBOUND;
149
152 Function& add_description(const std::string& description) LIEF_LIFETIMEBOUND;
153
155
156 private:
157 std::unique_ptr<details::Function> impl_;
158};
159
160}
161
162
163#endif
This class mirrors the DW_TAG_label DWARF tag.
Definition DWARF/editor/Function.hpp:97
Label(std::unique_ptr< details::FunctionLabel > impl)
This class mirrors the DW_TAG_lexical_block DWARF tag.
Definition DWARF/editor/Function.hpp:69
LexicalBlock & add_name(const std::string &name)
Create a DW_AT_name entry to associate a name to this entry.
std::unique_ptr< LexicalBlock > add_block(const std::vector< range_t > &range)
Create a sub-block with the given range of addresses.
LexicalBlock(std::unique_ptr< details::FunctionLexicalBlock > impl)
LexicalBlock & add_description(const std::string &description)
Create a DW_AT_description entry with the description provided in parameter.
std::unique_ptr< LexicalBlock > add_block(uint64_t start, uint64_t end)
Create a sub-block with the given low/high addresses.
This class represents a parameter of the current function (DW_TAG_formal_parameter).
Definition DWARF/editor/Function.hpp:51
Parameter(std::unique_ptr< details::FunctionParameter > impl)
Parameter & assign_register(const std::string &name)
Assign this parameter to a specific named register.
Parameter & assign_register(uint64_t reg)
Assign this parameter to the given DWARF register id (e.g. DW_OP_reg0).
Function(std::unique_ptr< details::Function > impl)
std::unique_ptr< Label > add_label(uint64_t addr, const std::string &label)
Add a label at the given address.
Function & set_external()
Set the function as external by defining DW_AT_external to true. This means that the function is impo...
Function & set_return_type(const Type &type)
Set the return type of this function.
std::unique_ptr< Variable > create_stack_variable(const std::string &name)
Create a stack-based variable owned by the current function.
Function & set_ranges(const std::vector< range_t > &ranges)
Set the ranges of addresses owned by the implementation of this function by setting the DW_AT_ranges ...
std::unique_ptr< Parameter > add_parameter(const std::string &name, const Type &type)
Add a parameter to the current function.
Function & set_low_high(uint64_t low, uint64_t high)
Set the upper and lower bound addresses for this function. This assumes that the function is contiguo...
Function & set_address(uint64_t addr)
Set the address of this function by defining DW_AT_entry_pc.
std::unique_ptr< LexicalBlock > add_lexical_block(uint64_t start, uint64_t end)
Add a lexical block with the given range.
Function & add_description(const std::string &description)
Create a DW_AT_description entry with the description provided in parameter.
This class is the base class for any types created when editing DWARF debug info.
Definition DWARF/editor/Type.hpp:36
This class represents an editable DWARF variable which can be scoped by a function or a compilation u...
Definition editor/Variable.hpp:34
#define LIEF_LIFETIMEBOUND
Definition compiler_attributes.hpp:72
Definition DWARF/editor/CompilationUnit.hpp:37
Definition Editor.hpp:32
uint64_t end
Definition DWARF/editor/Function.hpp:46
range_t(uint64_t start, uint64_t end)
Definition DWARF/editor/Function.hpp:42
uint64_t start
Definition DWARF/editor/Function.hpp:45
#define LIEF_API
Definition visibility.h:45