Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make LabelView sortable #80

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/ui/python/py_architecture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ namespace bp = boost::python;

MEDUSA_NAMESPACE_USE

template<>
Architecture const volatile *boost::get_pointer(Architecture const volatile *p)
{
return p;
}

void PydusaArchitecture(void)
{
bp::class_<Architecture, boost::noncopyable>("Architecture", bp::no_init)
Expand Down
6 changes: 6 additions & 0 deletions src/ui/python/py_cell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ namespace bp = boost::python;

MEDUSA_NAMESPACE_USE

template<>
Cell const volatile *boost::get_pointer(Cell const volatile *p)
{
return p;
}

void PydusaCell(void)
{
bp::enum_<Cell::Type>("CellType")
Expand Down
6 changes: 6 additions & 0 deletions src/ui/python/py_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ namespace bp = boost::python;

MEDUSA_NAMESPACE_USE

template<>
Loader const volatile *boost::get_pointer(Loader const volatile *p)
{
return p;
}

void PydusaLoader(void)
{
bp::class_<Loader, boost::noncopyable>("Loader", bp::no_init)
Expand Down
6 changes: 6 additions & 0 deletions src/ui/python/py_memory_area.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ namespace bp = boost::python;

MEDUSA_NAMESPACE_USE

template<>
MemoryArea const volatile *boost::get_pointer(MemoryArea const volatile *p)
{
return p;
}

namespace pydusa
{
}
Expand Down
34 changes: 32 additions & 2 deletions src/ui/qt/LabelView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,50 @@

#include <QStandardItemModel>
#include <QTreeWidgetItem>
#include <QFileInfo>
#include <QDir>

Q_DECLARE_METATYPE(medusa::Address);
Q_DECLARE_METATYPE(medusa::Label);

LabelView::LabelView(QWidget * parent, medusa::Medusa &core)
LabelView::LabelView(QWidget * parent, medusa::Medusa &core, QString const &fileName)
: QTreeView(parent), View(medusa::Document::Subscriber::LabelUpdated, core.GetDocument())
, _core(core)
{
// Look for a map file with the same base name as the binary file, and if such
// is present, record the listed symbols, indexed by address for later lookup.
// For now, ignorantly assume Microsoft Visual Studio linker map file format.
QFileInfo const fi(fileName);
QFile file(QFileInfo(fi.dir(), fi.completeBaseName() + ".map").filePath());
if (file.open(QIODevice::ReadOnly | QIODevice::Text))
{
while (!file.atEnd())
{
auto line = file.readLine();
int64_t addr;
char name[256];
if (sscanf(line, "%llx:%llx 0%llx", &addr, &addr, &addr) == 3)
{
// The line seems to belong to the section directory. Just ignore it.
}
else if (sscanf(line, "%llx:%llx %255s %llx", &addr, &addr, name, &addr) == 4)
{
// Now this seems worth recording.
_symbolMap[addr] = name;
}
}
}
setSortingEnabled(true);
setUniformRowHeights(false);
qRegisterMetaType<medusa::Address>("Address");
qRegisterMetaType<medusa::Label>("Label");
setEditTriggers(QAbstractItemView::NoEditTriggers);
auto model = new QStandardItemModel(this);
model->setColumnCount(3);
model->setColumnCount(4);
model->setHeaderData(0, Qt::Horizontal, "Name");
model->setHeaderData(1, Qt::Horizontal, "Type");
model->setHeaderData(2, Qt::Horizontal, "Address");
model->setHeaderData(3, Qt::Horizontal, "Symbol");
setModel(model);
connect(this, SIGNAL(doubleClicked(QModelIndex const&)), this, SLOT(onDoubleClickLabel(QModelIndex const&)));
connect(this, SIGNAL(labelAdded(medusa::Address const&, medusa::Label const&)), this, SLOT(onAddLabel(medusa::Address const&, medusa::Label const&)));
Expand Down Expand Up @@ -75,6 +102,9 @@ void LabelView::onAddLabel(medusa::Address const& address, medusa::Label const&
model->setData(model->index(row, 0), QString::fromStdString(label.GetLabel()));
model->setData(model->index(row, 1), labelType);
model->setData(model->index(row, 2), QString::fromStdString(address.ToString()));
auto it = _symbolMap.find(address.GetOffset());
if (it != _symbolMap.end())
model->setData(model->index(row, 3), QString::fromStdString(it->second));

// This method can assert
//resizeColumnToContents(0);
Expand Down
3 changes: 2 additions & 1 deletion src/ui/qt/LabelView.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class LabelView : public QTreeView, public medusa::View
Q_OBJECT

public:
LabelView(QWidget * parent, medusa::Medusa& core);
LabelView(QWidget * parent, medusa::Medusa& core, QString const &fileName);
virtual ~LabelView(void) {}

virtual void OnLabelUpdated(medusa::Address const& address, medusa::Label const& label, bool removed);
Expand All @@ -36,6 +36,7 @@ private slots:
private:
medusa::Medusa& _core;
QMutex _mutex;
std::map<int64_t, std::string> _symbolMap;
};

#endif // !__LABEL_VIEW_HPP__
4 changes: 2 additions & 2 deletions src/ui/qt/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ bool MainWindow::openDocument()
this->memAreaDock->setWidget(memAreaView);
connect(memAreaView, SIGNAL(goTo(medusa::Address const&)), this, SLOT(goTo(medusa::Address const&)));

auto labelView = new LabelView(this, _medusa);
auto labelView = new LabelView(this, _medusa, _fileName);
this->labelDock->setWidget(labelView);
connect(labelView, SIGNAL(goTo(medusa::Address const&)), this, SLOT(goTo(medusa::Address const&)));

Expand Down Expand Up @@ -147,7 +147,7 @@ bool MainWindow::loadDocument()
memAreaView->Refresh();
this->memAreaDock->setWidget(memAreaView);

auto labelView = new LabelView(this, _medusa);
auto labelView = new LabelView(this, _medusa, _fileName);
labelView->Refresh();
this->labelDock->setWidget(labelView);

Expand Down