Skip to content

Commit

Permalink
more minor modernizations
Browse files Browse the repository at this point in the history
  • Loading branch information
eteran committed Mar 21, 2024
1 parent c69406c commit f4c6dd3
Show file tree
Hide file tree
Showing 16 changed files with 61 additions and 60 deletions.
4 changes: 1 addition & 3 deletions plugins/DebuggerCore/unix/Posix.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
#include <chrono>
#include <cstdint>

namespace DebuggerCorePlugin {
namespace Posix {
namespace DebuggerCorePlugin::Posix {

void initialize();
int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
Expand All @@ -17,7 +16,6 @@ ssize_t read(int fd, void *buf, size_t count);
ssize_t write(int fd, const void *buf, size_t count);
bool wait_for_sigchld(std::chrono::milliseconds msecs);

}
}

#endif
4 changes: 1 addition & 3 deletions plugins/DebuggerCore/unix/Unix.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@
#include <QString>
#include <QtGlobal>

namespace DebuggerCorePlugin {
namespace Unix {
namespace DebuggerCorePlugin::Unix {

QMap<qlonglong, QString> exceptions();
QString exception_name(qlonglong value);
qlonglong exception_value(const QString &name);
Status execute_process(const QString &path, const QString &cwd, const QList<QByteArray> &args);

}
}

#endif
2 changes: 1 addition & 1 deletion plugins/DebuggerCore/unix/linux/PlatformProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class PlatformProcess final : public IProcess {
Status pause() override;
Status resume(edb::EventStatus status) override;
Status step(edb::EventStatus status) override;
bool isPaused() const override;
[[nodiscard]] bool isPaused() const override;

public:
std::size_t writeBytes(edb::address_t address, const void *buf, size_t len) override;
Expand Down
4 changes: 2 additions & 2 deletions plugins/DebuggerCore/unix/linux/PlatformThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ class PlatformThread final : public IThread {
#endif

private:
[[nodiscard]] unsigned long getDebugRegister(std::size_t n);
long setDebugRegister(std::size_t n, unsigned long value);
[[nodiscard]] unsigned long getDebugRegister(std::size_t n) const;
long setDebugRegister(std::size_t n, unsigned long value) const;

private:
DebuggerCore *core_ = nullptr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -840,9 +840,9 @@ Register findRegisterValue(const Names &names, const Regs &regs, const QString &

if (regNameFoundIter != end) {
return make_Register<BitSize>(regName, regs[regNameFoundIter - names.begin()] >> shift, type);
} else {
return Register();
}

return Register();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,15 +389,15 @@ class PlatformState final : public IState {
[[nodiscard]] int tag(size_t n) const;
[[nodiscard]] size_t stackPointer() const;
// Convert from ST(n) index n to Rx index x
[[nodiscard]] size_t RIndexToSTIndex(size_t index) const;
[[nodiscard]] size_t STIndexToRIndex(size_t index) const;
[[nodiscard]] size_t RIndexToSTIndex(size_t n) const;
[[nodiscard]] size_t STIndexToRIndex(size_t n) const;
// Restore the full FPU Tag Word from the ptrace-filtered version
[[nodiscard]] edb::value16 restoreTagWord(uint16_t twd) const;
[[nodiscard]] std::uint16_t reducedTagWord() const;
void clear();

private:
[[nodiscard]] int recreateTag(const edb::value80 value) const;
[[nodiscard]] int recreateTag(edb::value80 value) const;
[[nodiscard]] int makeTag(size_t n, uint16_t twd) const;
} x87;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ bool PlatformThread::fillStateFromSimpleRegs(PlatformState *state) {
state->fillFrom(regs);
fillSegmentBases(state);
return true;
} else {
perror("PTRACE_GETREGS failed");
return false;
}

perror("PTRACE_GETREGS failed");
return false;
}

/**
Expand Down Expand Up @@ -317,7 +317,7 @@ edb::address_t PlatformThread::instructionPointer() const {
* @param n
* @return
*/
unsigned long PlatformThread::getDebugRegister(std::size_t n) {
unsigned long PlatformThread::getDebugRegister(std::size_t n) const {
size_t drOffset = offsetof(struct user, u_debugreg) + n * sizeof(user::u_debugreg[0]);
return ptrace(PTRACE_PEEKUSER, tid_, drOffset, 0);
}
Expand All @@ -328,7 +328,7 @@ unsigned long PlatformThread::getDebugRegister(std::size_t n) {
* @param value
* @return
*/
long PlatformThread::setDebugRegister(std::size_t n, unsigned long value) {
long PlatformThread::setDebugRegister(std::size_t n, unsigned long value) const {
size_t drOffset = offsetof(struct user, u_debugreg) + n * sizeof(user::u_debugreg[0]);
return ptrace(PTRACE_POKEUSER, tid_, drOffset, value);
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/DebuggerCore/win32/PlatformProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class PlatformProcess : public IProcess {

Status resume(edb::EventStatus status) override;
Status step(edb::EventStatus status) override;
bool isPaused() const override;
[[nodiscard]] bool isPaused() const override;
QMap<edb::address_t, Patch> patches() const override;

private:
Expand Down
2 changes: 1 addition & 1 deletion plugins/DebuggerCore/win32/PlatformThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class PlatformThread : public IThread {
Status resume(edb::EventStatus status) override;

public:
bool isPaused() const override;
[[nodiscard]] bool isPaused() const override;

private:
DebuggerCore *core_ = nullptr;
Expand Down
9 changes: 5 additions & 4 deletions plugins/DumpState/DumpState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,11 @@ void DumpState::dumpLines(edb::address_t address, int lines) {
std::cout << hex_string(buf[j]) << " ";
}

for (int j = 0; j < 16; ++j) {
// TODO(eteran): why won't this compile with MSVC?
const uint8_t ch = buf[j].toUint();
std::cout << ((std::isprint(ch) || (std::isspace(ch) && (ch != '\f' && ch != '\t' && ch != '\r' && ch != '\n' && ch != '\x0b') && ch < 0x80)) ? static_cast<char>(ch) : '.');
for (const edb::value8 &b : buf) {
const uint8_t ch = b.toUint();
std::cout << ((std::isprint(ch) || (std::isspace(ch) && (ch != '\f' && ch != '\t' && ch != '\r' && ch != '\n' && ch != '\x0b') && ch < 0x80))
? static_cast<char>(ch)
: '.');
}

std::cout << "\n";
Expand Down
21 changes: 12 additions & 9 deletions plugins/InstructionInspector/Plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1160,8 +1160,8 @@ std::string runOBJCONV(std::vector<std::uint8_t> bytes, edb::address_t address)
QFile::remove(binaryFileName);

if (success) {
const auto output = process.readAllStandardOutput();
const auto err = process.readAllStandardError();
const QByteArray output = process.readAllStandardOutput();
const QByteArray err = process.readAllStandardError();

if (process.exitCode() != 0) {
return ("; got response: \"" + err + "\"").constData();
Expand All @@ -1171,15 +1171,18 @@ std::string runOBJCONV(std::vector<std::uint8_t> bytes, edb::address_t address)
return "; process crashed";
}

const auto lines = output.split('\n');
const QList<QByteArray> lines = output.split('\n');
QString result;
enum class LookingFor { FunctionBegin,
Instruction } mode = LookingFor::FunctionBegin;
const auto addrFormatted = address.toHexString().toUpper().replace(QRegExp("^0+"), "");
const auto addrTruncatedFormatted = (address & UINT32_MAX).toHexString().toUpper().replace(QRegExp("^0+"), "");
enum class LookingFor {
FunctionBegin,
Instruction,
} mode = LookingFor::FunctionBegin;

for (int L = 0; L < lines.size(); ++L) {
const auto line = QString::fromUtf8(lines[L]);
const QString addrFormatted = address.toHexString().toUpper().replace(QRegExp("^0+"), "");
const QString addrTruncatedFormatted = (address & UINT32_MAX).toHexString().toUpper().replace(QRegExp("^0+"), "");

for (const QByteArray &byteString : lines) {
const auto line = QString::fromUtf8(byteString);
switch (mode) {
case LookingFor::FunctionBegin:
if (line.contains(QRegExp("^; Instruction set:"))) {
Expand Down
26 changes: 13 additions & 13 deletions src/Debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,11 +410,11 @@ Debugger::Debugger(QWidget *parent)
setRIPAction_ = createAction(tr("&Set %1 to this Instruction").arg("RIP"), QKeySequence(tr("Ctrl+*")), &Debugger::mnuCPUSetEIP);
gotoRIPAction_ = createAction(tr("&Goto %1").arg("RIP"), QKeySequence(tr("*")), &Debugger::mnuCPUJumpToEIP);
#elif defined(EDB_X86)
setRIPAction_ = createAction(tr("&Set %1 to this Instruction").arg("EIP"), QKeySequence(tr("Ctrl+*")), &Debugger::mnuCPUSetEIP);
gotoRIPAction_ = createAction(tr("&Goto %1").arg("EIP"), QKeySequence(tr("*")), &Debugger::mnuCPUJumpToEIP);
setRIPAction_ = createAction(tr("&Set %1 to this Instruction").arg("EIP"), QKeySequence(tr("Ctrl+*")), &Debugger::mnuCPUSetEIP);
gotoRIPAction_ = createAction(tr("&Goto %1").arg("EIP"), QKeySequence(tr("*")), &Debugger::mnuCPUJumpToEIP);
#elif defined(EDB_ARM32) || defined(EDB_ARM64)
setRIPAction_ = createAction(tr("&Set %1 to this Instruction").arg("PC"), QKeySequence(tr("Ctrl+*")), &Debugger::mnuCPUSetEIP);
gotoRIPAction_ = createAction(tr("&Goto %1").arg("PC"), QKeySequence(tr("*")), &Debugger::mnuCPUJumpToEIP);
setRIPAction_ = createAction(tr("&Set %1 to this Instruction").arg("PC"), QKeySequence(tr("Ctrl+*")), &Debugger::mnuCPUSetEIP);
gotoRIPAction_ = createAction(tr("&Goto %1").arg("PC"), QKeySequence(tr("*")), &Debugger::mnuCPUJumpToEIP);
#else
#error "This doesn't initialize actions and will lead to crash"
#endif
Expand Down Expand Up @@ -1196,7 +1196,7 @@ void Debugger::showEvent(QShowEvent *) {
QScreen *screen = QGuiApplication::primaryScreen();
QRect sg = screen->geometry();
#else
QRect sg = desktop.screenGeometry();
QRect sg = desktop.screenGeometry();
#endif
int x = (sg.width() - this->width()) / 2;
int y = (sg.height() - this->height()) / 2;
Expand Down Expand Up @@ -2139,7 +2139,7 @@ void Debugger::mnuCPURunToThisLine() {
// Name: mnuCPUToggleBreakpoint
// Desc:
//------------------------------------------------------------------------------
void Debugger::mnuCPUToggleBreakpoint() {
void Debugger::mnuCPUToggleBreakpoint() const {
const edb::address_t address = cpuView_->selectedAddress();
edb::v1::toggle_breakpoint(address);
}
Expand All @@ -2166,7 +2166,7 @@ void Debugger::mnuCPUAddConditionalBreakpoint() {
// Name: mnuCPURemoveBreakpoint
// Desc:
//------------------------------------------------------------------------------
void Debugger::mnuCPURemoveBreakpoint() {
void Debugger::mnuCPURemoveBreakpoint() const {
const edb::address_t address = cpuView_->selectedAddress();
edb::v1::remove_breakpoint(address);
}
Expand Down Expand Up @@ -2233,7 +2233,7 @@ void Debugger::mnuCPUSetEIP() {
// Name: mnuCPUModify
// Desc:
//------------------------------------------------------------------------------
void Debugger::mnuCPUModify() {
void Debugger::mnuCPUModify() const {
const edb::address_t address = cpuView_->selectedAddress();
const unsigned int size = cpuView_->selectedSize();

Expand Down Expand Up @@ -2540,10 +2540,10 @@ edb::EventStatus Debugger::handleEvent(const std::shared_ptr<IDebugEvent> &event
}

//------------------------------------------------------------------------------
// Name: update_tab_caption
// Name: updateTabCaption
// Desc:
//------------------------------------------------------------------------------
void Debugger::updateTabCaption(const std::shared_ptr<QHexView> &view, edb::address_t start, edb::address_t end) {
void Debugger::updateTabCaption(const std::shared_ptr<QHexView> &view, edb::address_t start, edb::address_t end) const {
const int index = tabWidget_->indexOf(view.get());
const QString caption = tabWidget_->data(index).toString();

Expand All @@ -2555,7 +2555,7 @@ void Debugger::updateTabCaption(const std::shared_ptr<QHexView> &view, edb::addr
}

//------------------------------------------------------------------------------
// Name: update_data
// Name: updateData
// Desc:
//------------------------------------------------------------------------------
void Debugger::updateData(const std::shared_ptr<DataViewInfo> &v) {
Expand All @@ -2572,7 +2572,7 @@ void Debugger::updateData(const std::shared_ptr<DataViewInfo> &v) {
}

//------------------------------------------------------------------------------
// Name: clear_data
// Name: clearData
// Desc:
//------------------------------------------------------------------------------
void Debugger::clearData(const std::shared_ptr<DataViewInfo> &v) {
Expand All @@ -2593,7 +2593,7 @@ void Debugger::clearData(const std::shared_ptr<DataViewInfo> &v) {
// Name: doJumpToAddress
// Desc:
//------------------------------------------------------------------------------
void Debugger::doJumpToAddress(edb::address_t address, const std::shared_ptr<IRegion> &r, bool scroll_to) {
void Debugger::doJumpToAddress(edb::address_t address, const std::shared_ptr<IRegion> &r, bool scroll_to) const {

cpuView_->setRegion(r);
if (scroll_to && !cpuView_->addressShown(address)) {
Expand Down
10 changes: 5 additions & 5 deletions src/Debugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ private Q_SLOTS:
void mnuCPURemoveComment();
void mnuCPURunToThisLine();
void mnuCPURunToThisLinePassSignal();
void mnuCPUToggleBreakpoint();
void mnuCPUToggleBreakpoint() const;
void mnuCPUAddConditionalBreakpoint();
void mnuCPUFillNop();
void mnuCPUFillZero();
Expand All @@ -171,8 +171,8 @@ private Q_SLOTS:
void mnuCPUFollowInStack();
void mnuCPUJumpToAddress();
void mnuCPUJumpToEIP();
void mnuCPUModify();
void mnuCPURemoveBreakpoint();
void mnuCPUModify() const;
void mnuCPURemoveBreakpoint() const;
void mnuCPUSetEIP();
void mnuCPULabelAddress();
void breakPointToggled_triggered(edb::address_t);
Expand Down Expand Up @@ -248,7 +248,7 @@ private Q_SLOTS:
void createDataTab();
void deleteDataTab();
void detachFromProcess(DetachAction kill);
void doJumpToAddress(edb::address_t address, const std::shared_ptr<IRegion> &r, bool scroll_to);
void doJumpToAddress(edb::address_t address, const std::shared_ptr<IRegion> &r, bool scroll_to) const;
void finishPluginSetup();
void followRegisterInDump(bool tabbed);
void resumeExecution(ExceptionResume pass_exception, DebugMode mode, ResumeFlag flags);
Expand All @@ -264,7 +264,7 @@ private Q_SLOTS:
void updateDisassembly(edb::address_t address, const std::shared_ptr<IRegion> &r);
void updateMenuState(GuiState state);
void updateStackView(const State &state);
void updateTabCaption(const std::shared_ptr<QHexView> &view, edb::address_t start, edb::address_t end);
void updateTabCaption(const std::shared_ptr<QHexView> &view, edb::address_t start, edb::address_t end) const;

private:
template <class F>
Expand Down
6 changes: 3 additions & 3 deletions src/RegisterViewModelBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,13 @@ QByteArray CategoriesHolder::rawValue() const {
RegisterViewItem *CategoriesHolder::child(int visibleRow) {

// return visible row #visibleRow
for (std::size_t row = 0; row < categories.size(); ++row) {
if (categories[row]->visible()) {
for (const std::unique_ptr<Category> &category : categories) {
if (category->visible()) {
--visibleRow;
}

if (visibleRow == -1) {
return categories[row].get();
return category.get();
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/graph/GraphEdge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,12 @@ QLineF GraphEdge::shortenLineToNode(QLineF line) {
};

// for any that intersect, shorten the line appropriately
for (int i = 0; i < 4; ++i) {
for (const QLineF &polyLine : polyLines) {
QPointF intersectPoint;
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
QLineF::IntersectType intersectType = polyLines[i].intersects(line, &intersectPoint);
QLineF::IntersectType intersectType = polyLine.intersects(line, &intersectPoint);
#else
QLineF::IntersectType intersectType = polyLines[i].intersect(line, &intersectPoint);
QLineF::IntersectType intersectType = polyLine.intersect(line, &intersectPoint);
#endif
if (intersectType == QLineF::BoundedIntersection) {
line.setP2(intersectPoint);
Expand Down
5 changes: 3 additions & 2 deletions src/widgets/QDisassemblyView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2163,8 +2163,9 @@ void QDisassemblyView::restoreState(const QByteArray &stateBuffer) {
//------------------------------------------------------------------------------
void QDisassemblyView::restoreComments(QVariantList &comments_data) {
qDebug("restoreComments");
for (auto it = comments_data.begin(); it != comments_data.end(); ++it) {
QVariantMap data = it->toMap();

for (const QVariant &entry : comments_data) {
QVariantMap data = entry.toMap();
if (const Result<edb::address_t, QString> addr = edb::v1::string_to_address(data["address"].toString())) {
comments_.insert(*addr, data["comment"].toString());
}
Expand Down

0 comments on commit f4c6dd3

Please sign in to comment.