CodeobjDecoderComponent Class Reference#
Rocprofiler SDK Developer API 0.5.0
ROCm Profiling API and tools
|
rocprofiler::sdk::codeobj::disassembly::CodeobjDecoderComponent Class Reference
#include "rocprofiler-sdk/cxx/codeobj/code_printing.hpp"

Public Member Functions | |
CodeobjDecoderComponent (const char *codeobj_data, uint64_t codeobj_size) | |
~CodeobjDecoderComponent ()=default | |
std::optional< uint64_t > | va2fo (uint64_t vaddr) const |
std::unique_ptr< Instruction > | disassemble_instruction (uint64_t faddr, uint64_t vaddr) |
Data Fields | |
std::map< uint64_t, SymbolInfo > | m_symbol_map {} |
std::vector< std::shared_ptr< Instruction > > | instructions {} |
std::unique_ptr< DisassemblyInstance > | disassembly {} |
std::map< segment::address_range_t, std::string > | m_line_number_map {} |
Detailed Description
Definition at line 67 of file code_printing.hpp.
Constructor & Destructor Documentation
◆ CodeobjDecoderComponent()
|
inline |
Definition at line 87 of file code_printing.hpp.
88 {
89 ProtectedFd prot("");
90 if(::write(prot.m_fd, codeobj_data, codeobj_size) != static_cast<int64_t>(codeobj_size))
91 throw std::runtime_error("Could not write to temporary file!");
92
93 ::lseek(prot.m_fd, 0, SEEK_SET);
94 fsync(prot.m_fd);
95
96 m_line_number_map = {};
97
98 std::unique_ptr<Dwarf, void (*)(Dwarf*)> dbg(dwarf_begin(prot.m_fd, DWARF_C_READ),
99 [](Dwarf* _dbg) { dwarf_end(_dbg); });
100
101 if(dbg)
102 {
103 Dwarf_Off cu_offset{0}, next_offset;
104 size_t header_size;
105
106 std::map<uint64_t, std::string> line_addrs;
107
108 while(
109 dwarf_nextcu(
110 dbg.get(), cu_offset, &next_offset, &header_size, nullptr, nullptr, nullptr) ==
111 0)
112 {
113 Dwarf_Die die;
114 if(!dwarf_offdie(dbg.get(), cu_offset + header_size, &die)) continue;
115
116 Dwarf_Lines* lines;
117 size_t line_count;
118 if(dwarf_getsrclines(&die, &lines, &line_count) != 0) continue;
119
120 for(size_t i = 0; i < line_count; ++i)
121 {
122 Dwarf_Addr addr;
123 int line_number;
124 Dwarf_Line* line = dwarf_onesrcline(lines, i);
125
126 if(line && dwarf_lineaddr(line, &addr) == 0 &&
127 dwarf_lineno(line, &line_number) == 0 && line_number != 0)
128 {
129 std::string src = dwarf_linesrc(line, nullptr, nullptr);
130 auto dwarf_line = src + ':' + std::to_string(line_number);
131
132 if(line_addrs.find(addr) != line_addrs.end())
133 {
134 line_addrs.at(addr) += ' ' + dwarf_line;
135 continue;
136 }
137
138 line_addrs.emplace(addr, std::move(dwarf_line));
139 }
140 }
141 cu_offset = next_offset;
142 }
143
144 auto it = line_addrs.begin();
145 if(it != line_addrs.end())
146 {
147 while(std::next(it) != line_addrs.end())
148 {
149 uint64_t delta = std::next(it)->first - it->first;
150 auto segment = segment::address_range_t{it->first, delta, 0};
151 m_line_number_map.emplace(segment, std::move(it->second));
152 it++;
153 }
154 auto segment = segment::address_range_t{it->first, codeobj_size - it->first, 0};
155 m_line_number_map.emplace(segment, std::move(it->second));
156 }
157 }
158
159 // Can throw
160 disassembly = std::make_unique<DisassemblyInstance>(codeobj_data, codeobj_size);
161 try
162 {
164 } catch(...)
165 {}
166 }
std::map< segment::address_range_t, std::string > m_line_number_map
Definition code_printing.hpp:194
std::unique_ptr< DisassemblyInstance > disassembly
Definition code_printing.hpp:192
std::map< uint64_t, SymbolInfo > m_symbol_map
Definition code_printing.hpp:190
References disassembly, m_line_number_map, and m_symbol_map.
◆ ~CodeobjDecoderComponent()
|
default |
Member Function Documentation
◆ disassemble_instruction()
|
inline |
Definition at line 175 of file code_printing.hpp.
176 {
178
180 auto inst = std::make_unique<Instruction>(std::move(pair.first), pair.second);
181 inst->faddr = faddr;
182 inst->vaddr = vaddr;
183
186
187 return inst;
188 }
References disassembly, and m_line_number_map.
◆ va2fo()
|
inline |
Definition at line 169 of file code_printing.hpp.
References disassembly.
Field Documentation
◆ disassembly
std::unique_ptr<DisassemblyInstance> rocprofiler::sdk::codeobj::disassembly::CodeobjDecoderComponent::disassembly {} |
Definition at line 192 of file code_printing.hpp.
192{};
Referenced by CodeobjDecoderComponent(), disassemble_instruction(), and va2fo().
◆ instructions
std::vector<std::shared_ptr<Instruction> > rocprofiler::sdk::codeobj::disassembly::CodeobjDecoderComponent::instructions {} |
Definition at line 191 of file code_printing.hpp.
191{};
◆ m_line_number_map
std::map<segment::address_range_t, std::string> rocprofiler::sdk::codeobj::disassembly::CodeobjDecoderComponent::m_line_number_map {} |
Definition at line 194 of file code_printing.hpp.
194{};
Referenced by CodeobjDecoderComponent(), and disassemble_instruction().
◆ m_symbol_map
std::map<uint64_t, SymbolInfo> rocprofiler::sdk::codeobj::disassembly::CodeobjDecoderComponent::m_symbol_map {} |
The documentation for this class was generated from the following file:
- rocprofiler-sdk/cxx/codeobj/code_printing.hpp
Generated by