Play-/Source/ui_qt/DebugSupport/FunctionsView.cpp
Jean-Philip Desjardins f7184f143e Rename some strings.
2023-08-30 10:21:25 -04:00

58 lines
1.9 KiB
C++

#include "FunctionsView.h"
#include <QPushButton>
#include "ui_TagsView.h"
#include "ELF.h"
CFunctionsView::CFunctionsView(QMdiArea* parent)
: CTagsView(parent)
{
parent->addSubWindow(this);
setWindowTitle("Functions");
{
Strings strings;
strings.newTagString = tr("New Function");
strings.renameTagString = tr("Rename Function");
strings.tagNameString = tr("New Function Name:");
strings.tagAddressString = tr("New Function Address:");
strings.deleteTagConfirmString = tr("Are you sure you want to delete this function?");
strings.deleteModuleTagsConfirmString = tr("Are you sure you want to delete functions from module '%0'?");
SetStrings(strings);
}
auto btnImport = new QPushButton("Load ELF symbols", this);
ui->bottomButtonsLayout->addWidget(btnImport);
connect(btnImport, &QPushButton::clicked, this, &CFunctionsView::OnImportClick);
}
void CFunctionsView::SetContext(CMIPS* context, CBiosDebugInfoProvider* biosDebugInfoProvider)
{
CTagsView::SetContext(context, &context->m_Functions, biosDebugInfoProvider);
}
void CFunctionsView::OnImportClick()
{
if(!m_context) return;
for(auto moduleIterator(std::begin(m_modules));
std::end(m_modules) != moduleIterator; moduleIterator++)
{
const auto& module(*moduleIterator);
auto moduleImage = reinterpret_cast<CELF32*>(module.param);
if(!moduleImage) continue;
moduleImage->EnumerateSymbols([&](const ELF::ELFSYMBOL32& symbol, uint8 type, uint8 binding, const char* name) {
if(type == ELF::STT_FUNC)
{
//NOTE: This check for the section owning the symbol might not be necessary.
//Since we load the executable at the address specified by the program header
auto symbolSection = moduleImage->GetSection(symbol.nSectionIndex);
if(!symbolSection) return;
m_context->m_Functions.InsertTag(module.begin + (symbol.nValue - symbolSection->nStart), name);
}
});
}
RefreshList();
OnStateChange();
}