Play-/Source/ui_qt/DebugSupport/ELFSymbolView.cpp

128 lines
3.1 KiB
C++
Raw Normal View History

2019-12-21 18:36:40 +00:00
#include "ELFSymbolView.h"
#include "string_format.h"
#include "lexical_cast_ex.h"
#include <QLabel>
#include <QFontMetrics>
#include <QHeaderView>
CELFSymbolView::CELFSymbolView(QMdiSubWindow* parent, QLayout* groupBoxLayout)
2019-12-21 18:48:44 +00:00
: QWidget(parent)
2019-12-21 18:36:40 +00:00
{
QStringList colLabels = {"Name", "Address", "Size", "Type", "Binding", "Section"};
m_layout = new QVBoxLayout(this);
m_tableWidget = new QTableWidget(this);
m_tableWidget->setRowCount(0);
m_tableWidget->setColumnCount(6);
m_tableWidget->setHorizontalHeaderLabels(colLabels);
m_tableWidget->verticalHeader()->hide();
m_tableWidget->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
m_tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
m_tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
m_tableWidget->setSelectionMode(QAbstractItemView::SingleSelection);
m_layout->addWidget(m_tableWidget);
groupBoxLayout->addWidget(this);
hide();
}
void CELFSymbolView::Reset()
{
m_tableWidget->setRowCount(0);
}
void CELFSymbolView::SetELF(CELF* pELF)
{
m_pELF = pELF;
PopulateList();
}
void CELFSymbolView::PopulateList()
{
// m_sortState = SORT_STATE_NONE;
const char* sectionName = ".symtab";
2022-03-15 08:13:44 -04:00
auto pSymTab = m_pELF->FindSection(sectionName);
2019-12-21 18:36:40 +00:00
if(pSymTab == NULL) return;
const char* pStrTab = (const char*)m_pELF->GetSectionData(pSymTab->nIndex);
if(pStrTab == NULL) return;
2022-03-16 19:32:03 -04:00
auto symbols = reinterpret_cast<const CELF::ELFSYMBOL*>(m_pELF->FindSectionData(sectionName));
unsigned int count = pSymTab->nSize / sizeof(CELF::ELFSYMBOL);
2019-12-21 18:36:40 +00:00
2022-03-16 19:32:03 -04:00
m_tableWidget->setRowCount(count);
2019-12-21 18:36:40 +00:00
2022-03-16 19:32:03 -04:00
for(unsigned int i = 0; i < count; i++)
2019-12-21 18:36:40 +00:00
{
2022-03-16 19:32:03 -04:00
auto symbol = symbols[i];
2019-12-21 18:36:40 +00:00
int j = 0;
std::string sTemp;
2022-03-16 19:32:03 -04:00
m_tableWidget->setItem(i, j++, new QTableWidgetItem(pStrTab + symbol.nName));
m_tableWidget->setItem(i, j++, new QTableWidgetItem(lexical_cast_hex<std::string>(symbol.nValue, 8).c_str()));
m_tableWidget->setItem(i, j++, new QTableWidgetItem(lexical_cast_hex<std::string>(symbol.nSize, 8).c_str()));
2019-12-21 18:36:40 +00:00
2022-03-16 19:32:03 -04:00
switch(symbol.nInfo & 0x0F)
2019-12-21 18:36:40 +00:00
{
case 0x00:
sTemp = "STT_NOTYPE";
break;
case 0x01:
sTemp = "STT_OBJECT";
break;
case 0x02:
sTemp = "STT_FUNC";
break;
case 0x03:
sTemp = "STT_SECTION";
break;
case 0x04:
sTemp = "STT_FILE";
break;
default:
2022-03-16 19:32:03 -04:00
sTemp = string_format("%i", symbol.nInfo & 0x0F);
2019-12-21 18:36:40 +00:00
break;
}
m_tableWidget->setItem(i, j++, new QTableWidgetItem(sTemp.c_str()));
2022-03-16 19:32:03 -04:00
switch((symbol.nInfo >> 4) & 0xF)
2019-12-21 18:36:40 +00:00
{
case 0x00:
sTemp = "STB_LOCAL";
break;
case 0x01:
sTemp = "STB_GLOBAL";
break;
case 0x02:
sTemp = "STB_WEAK";
break;
default:
2022-03-16 19:32:03 -04:00
sTemp = string_format("%i", (symbol.nInfo >> 4) & 0x0F);
2019-12-21 18:36:40 +00:00
break;
}
m_tableWidget->setItem(i, j++, new QTableWidgetItem(sTemp.c_str()));
2022-03-16 19:32:03 -04:00
switch(symbol.nSectionIndex)
2019-12-21 18:36:40 +00:00
{
case 0:
sTemp = "SHN_UNDEF";
break;
case 0xFFF1:
sTemp = "SHN_ABS";
break;
default:
2022-03-16 19:32:03 -04:00
sTemp = string_format("%i", symbol.nSectionIndex);
2019-12-21 18:36:40 +00:00
break;
}
m_tableWidget->setItem(i, j++, new QTableWidgetItem(sTemp.c_str()));
}
}