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

132 lines
3.2 KiB
C++
Raw Permalink Normal View History

2019-12-21 18:36:40 +00:00
#include "ELFProgramView.h"
#include "string_format.h"
#include <QLabel>
#include <QFontMetrics>
template <typename ElfType>
CELFProgramView<ElfType>::CELFProgramView(QMdiSubWindow* parent, QLayout* groupBoxLayout)
2019-12-21 18:48:44 +00:00
: QWidget(parent)
2019-12-21 18:36:40 +00:00
{
std::vector<std::string> labelsStr = {"Type:", "Offset:", "Virtual Address:", "Physical Address:", "File Size:", "Memory Size:", "Flags:", "Alignment:"};
m_layout = new QVBoxLayout(this);
auto label = new QLabel(this);
QFontMetrics metric(label->font());
delete label;
auto labelWidth = metric.horizontalAdvance(labelsStr.back().c_str()) + 10;
for(auto labelStr : labelsStr)
{
auto horizontalLayout = new QHBoxLayout();
2019-12-21 18:36:40 +00:00
auto label = new QLabel(this);
label->setText(labelStr.c_str());
label->setFixedWidth(labelWidth);
horizontalLayout->addWidget(label);
auto lineEdit = new QLineEdit(this);
lineEdit->setReadOnly(true);
m_editFields.push_back(lineEdit);
horizontalLayout->addWidget(lineEdit);
m_layout->addLayout(horizontalLayout);
}
// blankLayout / blankWidget funtion is to exapnd and take the empty space
auto blankWidget = new QWidget(this);
auto blankLayout = new QVBoxLayout();
QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
blankWidget->setSizePolicy(sizePolicy);
blankLayout->addWidget(blankWidget);
m_layout->addLayout(blankLayout);
2019-12-21 18:36:40 +00:00
groupBoxLayout->addWidget(this);
hide();
}
template <typename ElfType>
void CELFProgramView<ElfType>::Reset()
2019-12-21 18:36:40 +00:00
{
for(auto editField : m_editFields)
{
editField->clear();
}
}
template <typename ElfType>
void CELFProgramView<ElfType>::SetProgram(int program)
2019-12-21 18:36:40 +00:00
{
FillInformation(program);
}
template <typename ElfType>
void CELFProgramView<ElfType>::SetELF(ElfType* pELF)
2019-12-21 18:36:40 +00:00
{
m_pELF = pELF;
}
template <typename ElfType>
void CELFProgramView<ElfType>::FillInformation(int program)
2019-12-21 18:36:40 +00:00
{
int i = 0;
std::string sTemp;
2022-03-15 08:13:44 -04:00
auto pH = m_pELF->GetProgram(program);
2019-12-21 18:36:40 +00:00
switch(pH->nType)
{
case ELF::PT_NULL:
2019-12-21 18:36:40 +00:00
sTemp = "PT_NULL";
break;
case ELF::PT_LOAD:
2019-12-21 18:36:40 +00:00
sTemp = "PT_LOAD";
break;
case ELF::PT_DYNAMIC:
2019-12-21 18:36:40 +00:00
sTemp = "PT_DYNAMIC";
break;
case ELF::PT_INTERP:
2019-12-21 18:36:40 +00:00
sTemp = "PT_INTERP";
break;
case ELF::PT_NOTE:
2019-12-21 18:36:40 +00:00
sTemp = "PT_NOTE";
break;
case ELF::PT_SHLIB:
2019-12-21 18:36:40 +00:00
sTemp = "PT_SHLIB";
break;
case ELF::PT_PHDR:
2019-12-21 18:36:40 +00:00
sTemp = "PT_PHDR";
break;
default:
sTemp = string_format("Unknown (0x%08X)", pH->nType);
break;
}
m_editFields[i++]->setText(sTemp.c_str());
sTemp = string_format("0x%08X", pH->nOffset);
m_editFields[i++]->setText(sTemp.c_str());
sTemp = string_format("0x%08X", pH->nVAddress);
m_editFields[i++]->setText(sTemp.c_str());
sTemp = string_format("0x%08X", pH->nPAddress);
m_editFields[i++]->setText(sTemp.c_str());
sTemp = string_format("0x%08X", pH->nFileSize);
m_editFields[i++]->setText(sTemp.c_str());
sTemp = string_format("0x%08X", pH->nMemorySize);
m_editFields[i++]->setText(sTemp.c_str());
sTemp = string_format("0x%08X", pH->nFlags);
m_editFields[i++]->setText(sTemp.c_str());
sTemp = string_format("0x%08X", pH->nAlignment);
m_editFields[i++]->setText(sTemp.c_str());
}
template class CELFProgramView<CELF32>;
template class CELFProgramView<CELF64>;