LIEF: Library to Instrument Executable Formats Version 0.17.0
Loading...
Searching...
No Matches
DWARF/editor/Function.hpp
Go to the documentation of this file.
1/* Copyright 2022 - 2025 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 <vector>
20#include <string>
21
22#include "LIEF/visibility.h"
23
24namespace LIEF {
25namespace dwarf {
26namespace editor {
27class Type;
28class Variable;
29
30namespace details {
31class Function;
32class FunctionParameter;
33class FunctionLexicalBlock;
34class FunctionLabel;
35}
36class LIEF_API Function {
39 public:
40 struct LIEF_API range_t {
41 range_t() = default;
42 range_t(uint64_t start, uint64_t end) :
43 start(start), end(end)
44 {}
45 uint64_t start = 0;
46 uint64_t end = 0;
47 };
48 class LIEF_API Parameter {
51 public:
52 Parameter() = delete;
53 Parameter(std::unique_ptr<details::FunctionParameter> impl);
54
56 private:
57 std::unique_ptr<details::FunctionParameter> impl_;
58 };
59 class LIEF_API LexicalBlock {
62 public:
63 LexicalBlock() = delete;
64 LexicalBlock(std::unique_ptr<details::FunctionLexicalBlock> impl);
65
67 private:
68 std::unique_ptr<details::FunctionLexicalBlock> impl_;
69 };
70 class LIEF_API Label {
73 public:
74 Label() = delete;
75 Label(std::unique_ptr<details::FunctionLabel> impl);
76
77 ~Label();
78 private:
79 std::unique_ptr<details::FunctionLabel> impl_;
80 };
81
82 Function() = delete;
83 Function(std::unique_ptr<details::Function> impl);
84 Function& set_address(uint64_t addr);
87 Function& set_low_high(uint64_t low, uint64_t high);
93 Function& set_ranges(const std::vector<range_t>& ranges);
99 Function& set_external();
104 Function& set_return_type(const Type& type);
107 std::unique_ptr<Parameter> add_parameter(const std::string& name, const Type& type);
110 std::unique_ptr<Variable> create_stack_variable(const std::string& name);
113 std::unique_ptr<LexicalBlock> add_lexical_block(uint64_t start, uint64_t end);
116 std::unique_ptr<Label> add_label(uint64_t addr, const std::string& label);
119
120 ~Function();
121
122 private:
123 std::unique_ptr<details::Function> impl_;
124};
125
126}
127}
128}
129#endif
LIEF::dwarf::editor::Function::Label::Label
Label()=delete
LIEF::dwarf::editor::Function::Label::~Label
~Label()
LIEF::dwarf::editor::Function::Label::Label
Label(std::unique_ptr< details::FunctionLabel > impl)
LIEF::dwarf::editor::Function::LexicalBlock::~LexicalBlock
~LexicalBlock()
LIEF::dwarf::editor::Function::LexicalBlock::LexicalBlock
LexicalBlock(std::unique_ptr< details::FunctionLexicalBlock > impl)
LIEF::dwarf::editor::Function::LexicalBlock::LexicalBlock
LexicalBlock()=delete
LIEF::dwarf::editor::Function::Parameter::Parameter
Parameter()=delete
LIEF::dwarf::editor::Function::Parameter::Parameter
Parameter(std::unique_ptr< details::FunctionParameter > impl)
LIEF::dwarf::editor::Function::Parameter::~Parameter
~Parameter()
LIEF::dwarf::editor::Function
This class represents an editable DWARF function (DW_TAG_subprogram)
Definition DWARF/editor/Function.hpp:38
LIEF::dwarf::editor::Function::Function
Function(std::unique_ptr< details::Function > impl)
LIEF::dwarf::editor::Function::add_label
std::unique_ptr< Label > add_label(uint64_t addr, const std::string &label)
Add a label at the given address.
LIEF::dwarf::editor::Function::set_external
Function & set_external()
Set the function as external by defining DW_AT_external to true. This means that the function is impo...
LIEF::dwarf::editor::Function::set_return_type
Function & set_return_type(const Type &type)
Set the return type of this function.
LIEF::dwarf::editor::Function::Function
Function()=delete
LIEF::dwarf::editor::Function::create_stack_variable
std::unique_ptr< Variable > create_stack_variable(const std::string &name)
Create a stack-based variable owned by the current function.
LIEF::dwarf::editor::Function::set_ranges
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 ...
LIEF::dwarf::editor::Function::add_parameter
std::unique_ptr< Parameter > add_parameter(const std::string &name, const Type &type)
Add a parameter to the current function.
LIEF::dwarf::editor::Function::~Function
~Function()
LIEF::dwarf::editor::Function::set_low_high
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...
LIEF::dwarf::editor::Function::set_address
Function & set_address(uint64_t addr)
Set the address of this function by defining DW_AT_entry_pc
LIEF::dwarf::editor::Function::add_lexical_block
std::unique_ptr< LexicalBlock > add_lexical_block(uint64_t start, uint64_t end)
Add a lexical block with the given range.
LIEF::dwarf::editor::Type
This class is the base class for any types created when editing DWARF debug info.
Definition DWARF/editor/Type.hpp:36
LIEF::dwarf::editor::Variable
This class represents an editable DWARF variable which can be scoped by a function or a compilation u...
Definition editor/Variable.hpp:33
LIEF::dwarf::editor::details
Definition DWARF/editor/CompilationUnit.hpp:36
LIEF::dwarf::editor
Definition Editor.hpp:30
LIEF::dwarf
Namespace for the DWARF debug format.
Definition DWARF/CompilationUnit.hpp:28
LIEF
LIEF namespace.
Definition Abstract/Binary.hpp:39
LIEF::dwarf::editor::Function::range_t::range_t
range_t()=default
LIEF::dwarf::editor::Function::range_t::range_t
range_t(uint64_t start, uint64_t end)
Definition DWARF/editor/Function.hpp:42
visibility.h
LIEF_API
#define LIEF_API
Definition visibility.h:41