2019-12-10 12:31:00 +00:00
|
|
|
#include "FunctionsView.h"
|
2023-08-12 10:29:24 -04:00
|
|
|
#include <QPushButton>
|
|
|
|
#include "ui_TagsView.h"
|
|
|
|
#include "ELF.h"
|
2020-05-18 19:12:45 +01:00
|
|
|
|
2019-12-10 12:31:00 +00:00
|
|
|
CFunctionsView::CFunctionsView(QMdiArea* parent)
|
2023-08-12 10:29:24 -04:00
|
|
|
: CTagsView(parent)
|
2019-12-10 12:31:00 +00:00
|
|
|
{
|
2019-12-20 16:03:07 +00:00
|
|
|
parent->addSubWindow(this);
|
|
|
|
setWindowTitle("Functions");
|
2019-12-10 12:31:00 +00:00
|
|
|
|
2019-12-10 12:47:29 +00:00
|
|
|
auto btnImport = new QPushButton("Load ELF symbols", this);
|
2023-08-12 10:29:24 -04:00
|
|
|
ui->bottomButtonsLayout->addWidget(btnImport);
|
2019-12-10 12:47:29 +00:00
|
|
|
|
|
|
|
connect(btnImport, &QPushButton::clicked, this, &CFunctionsView::OnImportClick);
|
2019-12-10 12:31:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CFunctionsView::SetContext(CMIPS* context, CBiosDebugInfoProvider* biosDebugInfoProvider)
|
|
|
|
{
|
2023-08-12 10:29:24 -04:00
|
|
|
CTagsView::SetContext(context, &context->m_Functions, biosDebugInfoProvider);
|
2019-12-10 12:47:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CFunctionsView::OnImportClick()
|
|
|
|
{
|
|
|
|
if(!m_context) return;
|
|
|
|
|
|
|
|
for(auto moduleIterator(std::begin(m_modules));
|
|
|
|
std::end(m_modules) != moduleIterator; moduleIterator++)
|
|
|
|
{
|
|
|
|
const auto& module(*moduleIterator);
|
2023-07-31 18:21:18 -04:00
|
|
|
auto moduleImage = reinterpret_cast<CELF32*>(module.param);
|
|
|
|
if(!moduleImage) continue;
|
2019-12-10 12:47:29 +00:00
|
|
|
|
2023-07-31 18:21:18 -04:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
});
|
2019-12-10 12:47:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RefreshList();
|
2023-08-12 10:29:24 -04:00
|
|
|
OnStateChange();
|
2019-12-10 12:47:29 +00:00
|
|
|
}
|