Skip to content

Commit

Permalink
add detection for inlined code in disassembly
Browse files Browse the repository at this point in the history
this adds a dector to detect and hide inlined code in the disassembly
  • Loading branch information
lievenhey committed Jul 4, 2023
1 parent 136afd8 commit 7d30963
Show file tree
Hide file tree
Showing 6 changed files with 313 additions and 29 deletions.
1 change: 1 addition & 0 deletions src/models/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ add_library(
codedelegate.cpp
costdelegate.cpp
data.cpp
disassemblyentry.cpp
disassemblymodel.cpp
disassemblyoutput.cpp
eventmodel.cpp
Expand Down
99 changes: 99 additions & 0 deletions src/models/disassemblyentry.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
SPDX-FileCopyrightText: Lieven Hey <[email protected]>
SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company, [email protected]
SPDX-License-Identifier: GPL-2.0-or-later
*/

#include "disassemblyentry.h"

DisassemblyEntry::DisassemblyEntry(DisassemblyEntry* parent, int row,
const DisassemblyOutput::DisassemblyLine& disassemblyLine, QTextLine textLine)
: m_parent(parent)
, m_disassemblyLine(disassemblyLine)
, m_textLine(textLine)
, m_row(row)
{
}

DisassemblyEntry* DisassemblyEntry::lastChild()
{
if (m_lines.isEmpty()) {
return nullptr;
}

return &m_lines[m_lines.size() - 1];
}

void DisassemblyEntry::addChild(const DisassemblyEntry& line)
{
m_lines.push_back(line);
}

void DisassemblyEntry::clear()
{
m_lines.clear();
}

DisassemblyEntry::Iterator::Iterator(const DisassemblyEntry* entry, int child)
: m_entry(const_cast<DisassemblyEntry*>(entry))
, m_child(child)
{
}

DisassemblyEntry& DisassemblyEntry::Iterator::operator*() const
{
if (m_child == -1) {
return *m_entry;
}
return *m_entry->child(m_child);
}

DisassemblyEntry* DisassemblyEntry::Iterator::operator->() const
{
if (m_child == -1) {
return m_entry;
}
return m_entry->child(m_child);
}

DisassemblyEntry::Iterator& DisassemblyEntry::Iterator::operator++()
{
if (m_child == -1) {
m_entry++;
if (m_entry->childCount() > 0) {
m_child = 0;
} else {
m_child = -1;
}
return *this;
}

m_child++;

if (m_child >= m_entry->childCount()) {
m_entry++;
if (m_entry->childCount() > 0) {
m_child = 0;
} else {
m_child = -1;
}
}

return *this;
}

bool DisassemblyEntry::Iterator::operator==(const DisassemblyEntry::Iterator& other) const
{
return this->m_entry == other.m_entry && this->m_child == other.m_child;
}

DisassemblyEntry::Iterator DisassemblyEntry::begin() const
{
return Iterator(&m_lines[0], m_lines[0].childCount() == 0 ? -1 : 0);
}

DisassemblyEntry::Iterator DisassemblyEntry::end() const
{
return Iterator(m_lines.end(), -1);
}
93 changes: 93 additions & 0 deletions src/models/disassemblyentry.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
SPDX-FileCopyrightText: Lieven Hey <[email protected]>
SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company, [email protected]
SPDX-License-Identifier: GPL-2.0-or-later
*/

#pragma once

#include "disassemblyoutput.h"
#include <iterator>
#include <QTextLine>
#include <QVector>

class DisassemblyEntry
{
public:
DisassemblyEntry(DisassemblyEntry* parent, int row, const DisassemblyOutput::DisassemblyLine& disassemblyLine = {},
QTextLine textLine = {});

~DisassemblyEntry() = default;

DisassemblyEntry* parent() const
{
return m_parent;
}

int row() const
{
return m_row;
}

DisassemblyEntry* child(int row)
{
return &m_lines[row];
}

DisassemblyEntry* lastChild();

DisassemblyOutput::DisassemblyLine disassemblyLine() const
{
return m_disassemblyLine;
}

QTextLine textLine() const
{
return m_textLine;
}

int childCount() const
{
return m_lines.size();
}

void clear();
void addChild(const DisassemblyEntry& line);

class Iterator : public std::iterator<std::forward_iterator_tag, DisassemblyEntry>
{
public:
Iterator(const DisassemblyEntry* entry, int child);
DisassemblyEntry& operator*() const;
DisassemblyEntry* operator->() const;

Iterator& operator++();
Iterator operator++(int)
{
Iterator tmp = *this;
++(*this);
return tmp;
}

bool operator==(const Iterator& other) const;
bool operator!=(const Iterator& other) const
{
return !(*this == other);
}

private:
DisassemblyEntry* m_entry = nullptr;
int m_child = -1;
};

Iterator begin() const;
Iterator end() const;

private:
DisassemblyEntry* m_parent;
QVector<DisassemblyEntry> m_lines;
DisassemblyOutput::DisassemblyLine m_disassemblyLine;
QTextLine m_textLine;
int m_row;
};
Loading

0 comments on commit 7d30963

Please sign in to comment.