LoadedCodeobjDecoder Class Reference

LoadedCodeobjDecoder Class Reference#

Rocprofiler SDK Developer API: rocprofiler::sdk::codeobj::disassembly::LoadedCodeobjDecoder Class Reference
Rocprofiler SDK Developer API 0.5.0
ROCm Profiling API and tools
rocprofiler::sdk::codeobj::disassembly::LoadedCodeobjDecoder Class Reference

#include "rocprofiler-sdk/cxx/codeobj/code_printing.hpp"

+ Collaboration diagram for rocprofiler::sdk::codeobj::disassembly::LoadedCodeobjDecoder:

Public Member Functions

 LoadedCodeobjDecoder (const char *filepath, uint64_t _load_addr, uint64_t _memsize)
 
 LoadedCodeobjDecoder (const void *data, uint64_t size, uint64_t _load_addr, unsigned long _memsize)
 
std::unique_ptr< Instructionget (uint64_t ld_addr)
 
uint64_t begin () const
 
uint64_t end () const
 
uint64_t size () const
 
bool inrange (uint64_t addr) const
 
const char * getSymbolName (uint64_t addr) const
 
std::map< uint64_t, SymbolInfo > & getSymbolMap () const
 

Data Fields

const uint64_t load_addr
 

Detailed Description

Definition at line 197 of file code_printing.hpp.

Constructor & Destructor Documentation

◆ LoadedCodeobjDecoder() [1/2]

rocprofiler::sdk::codeobj::disassembly::LoadedCodeobjDecoder::LoadedCodeobjDecoder ( const char *  filepath,
uint64_t  _load_addr,
uint64_t  _memsize 
)
inline

Definition at line 200 of file code_printing.hpp.

201 : load_addr(_load_addr)
202 , load_end(_load_addr + _memsize)
203 {
204 if(!filepath) throw std::runtime_error("Empty filepath.");
205
206 std::string_view fpath(filepath);
207
208 if(fpath.rfind(".out") + 4 == fpath.size())
209 {
210 std::ifstream file(filepath, std::ios::in | std::ios::binary);
211
212 if(!file.is_open()) throw std::runtime_error("Invalid file " + std::string(filepath));
213
214 std::vector<char> buffer;
215 file.seekg(0, file.end);
216 buffer.resize(file.tellg());
217 file.seekg(0, file.beg);
218 file.read(buffer.data(), buffer.size());
219
220 decoder = std::make_unique<CodeobjDecoderComponent>(buffer.data(), buffer.size());
221 }
222 else
223 {
224 std::unique_ptr<CodeObjectBinary> binary = std::make_unique<CodeObjectBinary>(filepath);
225 auto& buffer = binary->buffer;
226 decoder = std::make_unique<CodeobjDecoderComponent>(buffer.data(), buffer.size());
227 }
228 }

◆ LoadedCodeobjDecoder() [2/2]

rocprofiler::sdk::codeobj::disassembly::LoadedCodeobjDecoder::LoadedCodeobjDecoder ( const void *  data,
uint64_t  size,
uint64_t  _load_addr,
unsigned long  _memsize 
)
inline

Definition at line 229 of file code_printing.hpp.

230 : load_addr(_load_addr)
231 , load_end(load_addr + _memsize)
232 {
233 decoder =
234 std::make_unique<CodeobjDecoderComponent>(reinterpret_cast<const char*>(data), size);
235 }

References size().

+ Here is the call graph for this function:

Member Function Documentation

◆ begin()

uint64_t rocprofiler::sdk::codeobj::disassembly::LoadedCodeobjDecoder::begin ( ) const
inline

Definition at line 250 of file code_printing.hpp.

250{ return load_addr; };

References load_addr.

Referenced by inrange().

+ Here is the caller graph for this function:

◆ end()

uint64_t rocprofiler::sdk::codeobj::disassembly::LoadedCodeobjDecoder::end ( ) const
inline

Definition at line 251 of file code_printing.hpp.

251{ return load_end; }

Referenced by inrange().

+ Here is the caller graph for this function:

◆ get()

std::unique_ptr< Instruction > rocprofiler::sdk::codeobj::disassembly::LoadedCodeobjDecoder::get ( uint64_t  ld_addr)
inline

Definition at line 236 of file code_printing.hpp.

237 {
238 if(!decoder || ld_addr < load_addr) return nullptr;
239
240 uint64_t voffset = ld_addr - load_addr;
241 auto faddr = decoder->va2fo(voffset);
242 if(!faddr) return nullptr;
243
244 auto unique = decoder->disassemble_instruction(*faddr, voffset);
245 if(unique == nullptr || unique->size == 0) return nullptr;
246 unique->ld_addr = ld_addr;
247 return unique;
248 }

References load_addr.

◆ getSymbolMap()

std::map< uint64_t, SymbolInfo > & rocprofiler::sdk::codeobj::disassembly::LoadedCodeobjDecoder::getSymbolMap ( ) const
inline

Definition at line 265 of file code_printing.hpp.

266 {
267 if(!decoder) throw std::exception();
268 return decoder->m_symbol_map;
269 }

◆ getSymbolName()

const char * rocprofiler::sdk::codeobj::disassembly::LoadedCodeobjDecoder::getSymbolName ( uint64_t  addr) const
inline

Definition at line 255 of file code_printing.hpp.

256 {
257 if(!decoder) return nullptr;
258
259 auto it = decoder->m_symbol_map.find(addr - load_addr);
260 if(it != decoder->m_symbol_map.end()) return it->second.name.data();
261
262 return nullptr;
263 }

References load_addr.

◆ inrange()

bool rocprofiler::sdk::codeobj::disassembly::LoadedCodeobjDecoder::inrange ( uint64_t  addr) const
inline

Definition at line 253 of file code_printing.hpp.

References begin(), and end().

+ Here is the call graph for this function:

◆ size()

uint64_t rocprofiler::sdk::codeobj::disassembly::LoadedCodeobjDecoder::size ( ) const
inline

Definition at line 252 of file code_printing.hpp.

252{ return load_end - load_addr; }

References load_addr.

Referenced by LoadedCodeobjDecoder().

+ Here is the caller graph for this function:

Field Documentation

◆ load_addr

const uint64_t rocprofiler::sdk::codeobj::disassembly::LoadedCodeobjDecoder::load_addr

Definition at line 270 of file code_printing.hpp.

Referenced by begin(), get(), getSymbolName(), and size().


The documentation for this class was generated from the following file: