SDK: remove majority of exceptions (#176)
* SDK: remove majority of exceptions - replace with ROCP_FATAL, ROCP_CI_LOG(WARNING), etc. - improve logging of symbolic link - add --readlink and --realpath (hidden options) to rocprofv3 to follow symlinks for preloaded libraries * Add rocprofv3 --rocm-root argument * Fix registration resolved_exists * Fix rocprofv3_avail.py * Update logging for rocprofiler_configure search - relax failure conditions * Misc clang-tidy fixes * Fix merge * Fix merge --------- Co-authored-by: Jonathan R. Madsen <jonathanrmadsen@gmail.com> Co-authored-by: Bhardwaj, Gopesh <Gopesh.Bhardwaj@amd.com>
This commit is contained in:
@@ -22,6 +22,9 @@
|
||||
|
||||
#include "lib/common/elf_utils.hpp"
|
||||
|
||||
#include <rocprofiler-sdk/cxx/utility.hpp>
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <elfio/elfio.hpp>
|
||||
|
||||
#include <sys/stat.h>
|
||||
@@ -47,22 +50,14 @@ namespace
|
||||
{
|
||||
const ELFIO::Elf_Xword PAGE_SIZE = sysconf(_SC_PAGESIZE);
|
||||
|
||||
template <typename Tp>
|
||||
std::string
|
||||
as_hex_string(Tp&& _v, size_t _w = 16)
|
||||
{
|
||||
auto _ss = std::stringstream{};
|
||||
_ss.fill('0');
|
||||
_ss << "0x" << std::hex << std::setw(_w) << std::forward<Tp>(_v);
|
||||
return _ss.str();
|
||||
}
|
||||
using ::rocprofiler::sdk::utility::as_hex;
|
||||
} // namespace
|
||||
|
||||
SymbolEntry::SymbolEntry(unsigned int _idx, const accessor_type& _accessor)
|
||||
: index{_idx}
|
||||
{
|
||||
if(!_accessor.get_symbol(index, name, value, size, bind, type, section_index, other))
|
||||
throw std::runtime_error("Error in ELFIO::symbol_section_accessor::get_symbol");
|
||||
ROCP_WARNING << "ELFIO::symbol_section_accessor::get_symbol failed of symbol " << _idx;
|
||||
}
|
||||
|
||||
DynamicEntry::DynamicEntry(unsigned int _idx, const accessor_type& _accessor)
|
||||
@@ -75,7 +70,7 @@ RelocationEntry::RelocationEntry(unsigned int _idx, const accessor_type& _access
|
||||
: index{_idx}
|
||||
{
|
||||
if(!_accessor.get_entry(_idx, offset, symbol, type, addend))
|
||||
throw std::runtime_error("Error in ELFIO::relocation_section_accessor::get_entry");
|
||||
ROCP_WARNING << "ELFIO::relocation_section_accessor::get_entry failed for symbol " << _idx;
|
||||
}
|
||||
|
||||
ElfInfo::ElfInfo(std::string _fname)
|
||||
@@ -111,24 +106,25 @@ read(const std::string& _inp)
|
||||
|
||||
ROCP_TRACE << "\nReading " << _inp;
|
||||
|
||||
if(!reader.load(_inp)) throw std::runtime_error("Could not load elf file " + _inp);
|
||||
if(!reader.load(_inp))
|
||||
ROCP_WARNING << fmt::format("ELF parsing for '{}' did not succeed", _inp);
|
||||
|
||||
if(reader.get_class() == ELFIO::ELFCLASS32)
|
||||
ROCP_TRACE << "ELF 32-bit";
|
||||
ROCP_TRACE << " - ELF 32-bit";
|
||||
else
|
||||
ROCP_TRACE << "ELF 64-bit";
|
||||
ROCP_TRACE << " - ELF 64-bit";
|
||||
|
||||
ROCP_TRACE << "ELF file encoding: "
|
||||
ROCP_TRACE << " - ELF file encoding: "
|
||||
<< ((reader.get_encoding() == ELFIO::ELFDATA2LSB) ? std::string_view{"Little endian"}
|
||||
: std::string_view{"Big endian"});
|
||||
|
||||
ROCP_TRACE << "ELF version: " << reader.get_elf_version();
|
||||
ROCP_TRACE << "ELF header size: " << reader.get_header_size();
|
||||
ROCP_TRACE << "ELF OS ABI: " << reader.get_os_abi();
|
||||
ROCP_TRACE << " - ELF version: " << reader.get_elf_version();
|
||||
ROCP_TRACE << " - ELF header size: " << reader.get_header_size();
|
||||
ROCP_TRACE << " - ELF OS ABI: " << reader.get_os_abi();
|
||||
|
||||
// Print ELF file sections info
|
||||
ELFIO::Elf_Half sec_num = reader.sections.size();
|
||||
ROCP_TRACE << "Number of sections: " << sec_num;
|
||||
ROCP_TRACE << " - Number of sections: " << sec_num;
|
||||
|
||||
for(ELFIO::Elf_Half j = 0; j < sec_num; ++j)
|
||||
{
|
||||
@@ -143,85 +139,85 @@ read(const std::string& _inp)
|
||||
for(ELFIO::Elf_Half j = 0; j < sec_num; ++j)
|
||||
{
|
||||
Section* psec = sections.at(j);
|
||||
ROCP_TRACE << " [" << j << "] \t" << std::setw(20) << psec->get_name() << "\t : \t"
|
||||
ROCP_TRACE << " [" << j << "] \t" << std::setw(20) << psec->get_name() << "\t : \t"
|
||||
<< "size / entry-size = " << std::setw(6) << psec->get_size() << " / "
|
||||
<< std::setw(3) << psec->get_entry_size()
|
||||
<< " | addr: " << as_hex_string(psec->get_address())
|
||||
<< " | offset: " << as_hex_string(psec->get_offset());
|
||||
<< " | addr: " << as_hex(psec->get_address(), 16)
|
||||
<< " | offset: " << as_hex(psec->get_offset(), 16);
|
||||
|
||||
if(psec->get_size() == 0) continue;
|
||||
|
||||
if(psec->get_type() == ELFIO::SHT_SYMTAB)
|
||||
{
|
||||
const ELFIO::symbol_section_accessor _symbols(reader, psec);
|
||||
ROCP_TRACE << " Number of symbol entries: " << _symbols.get_symbols_num();
|
||||
ROCP_TRACE << " - Number of symbol entries: " << _symbols.get_symbols_num();
|
||||
for(ELFIO::Elf_Xword k = 0; k < _symbols.get_symbols_num(); ++k)
|
||||
symbol_entries.emplace_back(k, _symbols);
|
||||
}
|
||||
else if(psec->get_type() == ELFIO::SHT_DYNSYM)
|
||||
{
|
||||
const ELFIO::symbol_section_accessor _symbols(reader, psec);
|
||||
ROCP_TRACE << " Number of dynamic symbol entries: " << _symbols.get_symbols_num();
|
||||
ROCP_TRACE << " - Number of dynamic symbol entries: " << _symbols.get_symbols_num();
|
||||
for(ELFIO::Elf_Xword k = 0; k < _symbols.get_symbols_num(); ++k)
|
||||
dynamic_symbol_entries.emplace_back(k, _symbols);
|
||||
}
|
||||
else if(psec->get_type() == ELFIO::SHT_DYNAMIC)
|
||||
{
|
||||
const ELFIO::dynamic_section_accessor dynamic{reader, psec};
|
||||
ROCP_TRACE << " Number of dynamic entries: " << dynamic.get_entries_num();
|
||||
ROCP_TRACE << " - Number of dynamic entries: " << dynamic.get_entries_num();
|
||||
for(ELFIO::Elf_Xword k = 0; k < dynamic.get_entries_num(); ++k)
|
||||
dynamic_entries.emplace_back(k, dynamic);
|
||||
}
|
||||
else if(psec->get_type() == ELFIO::SHT_REL || psec->get_type() == ELFIO::SHT_RELA)
|
||||
{
|
||||
const ELFIO::relocation_section_accessor reloc{reader, psec};
|
||||
ROCP_TRACE << " Number of relocation entries: " << reloc.get_entries_num();
|
||||
ROCP_TRACE << " - Number of relocation entries: " << reloc.get_entries_num();
|
||||
for(ELFIO::Elf_Xword k = 0; k < reloc.get_entries_num(); ++k)
|
||||
reloc_entries.emplace_back(k, reloc);
|
||||
}
|
||||
}
|
||||
|
||||
ROCP_TRACE << "Symbols:";
|
||||
ROCP_TRACE << " - Symbols:";
|
||||
for(size_t k = 0; k < symbol_entries.size(); ++k)
|
||||
{
|
||||
if(!symbol_entries.at(k).name.empty())
|
||||
ROCP_TRACE << " [" << k << "] " << symbol_entries.at(k).name;
|
||||
ROCP_TRACE << " [" << k << "] " << symbol_entries.at(k).name;
|
||||
}
|
||||
|
||||
ROCP_TRACE << "Dynamic Symbols:";
|
||||
ROCP_TRACE << " - Dynamic Symbols:";
|
||||
for(size_t k = 0; k < dynamic_symbol_entries.size(); ++k)
|
||||
{
|
||||
if(!dynamic_symbol_entries.at(k).name.empty())
|
||||
ROCP_TRACE << " [" << k << "] " << dynamic_symbol_entries.at(k).name;
|
||||
ROCP_TRACE << " [" << k << "] " << dynamic_symbol_entries.at(k).name;
|
||||
}
|
||||
|
||||
ROCP_TRACE << "Dynamic entries:";
|
||||
ROCP_TRACE << " - Dynamic entries:";
|
||||
for(size_t k = 0; k < dynamic_entries.size(); ++k)
|
||||
{
|
||||
if(!dynamic_entries.at(k).name.empty())
|
||||
ROCP_TRACE << " [" << k << "] " << dynamic_entries.at(k).name;
|
||||
ROCP_TRACE << " [" << k << "] " << dynamic_entries.at(k).name;
|
||||
}
|
||||
|
||||
ROCP_TRACE << "Relocation entries:";
|
||||
ROCP_TRACE << " - Relocation entries:";
|
||||
for(size_t k = 0; k < reloc_entries.size(); ++k)
|
||||
{
|
||||
auto _sym_idx = reloc_entries.at(k).symbol;
|
||||
auto _name = std::string{};
|
||||
if(_sym_idx < symbol_entries.size()) _name = symbol_entries.at(_sym_idx).name;
|
||||
if(!_name.empty()) ROCP_TRACE << " [" << k << "] " << _name;
|
||||
if(!_name.empty()) ROCP_TRACE << " [" << k << "] " << _name;
|
||||
}
|
||||
|
||||
// Print ELF file segments info
|
||||
ELFIO::Elf_Half seg_num = reader.segments.size();
|
||||
ROCP_TRACE << "Number of segments: " << seg_num;
|
||||
ROCP_TRACE << " - Number of segments: " << seg_num;
|
||||
for(ELFIO::Elf_Half j = 0; j < seg_num; ++j)
|
||||
{
|
||||
const ELFIO::segment* pseg = reader.segments[j];
|
||||
ROCP_TRACE << " [" << std::setw(2) << j << "] flags: " << as_hex_string(pseg->get_flags())
|
||||
<< " offset: " << as_hex_string(pseg->get_offset())
|
||||
<< " align: " << as_hex_string(pseg->get_align())
|
||||
<< " virt: " << as_hex_string(pseg->get_virtual_address())
|
||||
<< " phys: " << as_hex_string(pseg->get_physical_address())
|
||||
ROCP_TRACE << " [" << std::setw(2) << j << "] flags: " << as_hex(pseg->get_flags(), 16)
|
||||
<< " offset: " << as_hex(pseg->get_offset(), 16)
|
||||
<< " align: " << as_hex(pseg->get_align(), 16)
|
||||
<< " virt: " << as_hex(pseg->get_virtual_address(), 16)
|
||||
<< " phys: " << as_hex(pseg->get_physical_address(), 16)
|
||||
<< " fsize: " << std::setw(8) << pseg->get_file_size()
|
||||
<< " msize: " << std::setw(8) << pseg->get_memory_size();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user