Skip to content

Commit

Permalink
more stylistic stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
eteran committed Mar 18, 2024
1 parent 257d01c commit c137554
Show file tree
Hide file tree
Showing 21 changed files with 147 additions and 78 deletions.
2 changes: 1 addition & 1 deletion include/GraphEdge.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class GraphEdge final : public QGraphicsItemGroup {
public:
enum { Type = UserType + 3 };

int type() const override {
[[nodiscard]] int type() const override {
// Enable the use of qgraphicsitem_cast with this item.
return Type;
}
Expand Down
2 changes: 1 addition & 1 deletion include/GraphNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class GraphNode final : public QGraphicsItem {
public:
enum { Type = UserType + 2 };

int type() const override {
[[nodiscard]] int type() const override {
// Enable the use of qgraphicsitem_cast with this item.
return Type;
}
Expand Down
10 changes: 5 additions & 5 deletions include/IAnalyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ class IAnalyzer {
};

public:
virtual AddressCategory category(edb::address_t address) const = 0;
virtual FunctionMap functions(const std::shared_ptr<IRegion> &region) const = 0;
virtual FunctionMap functions() const = 0;
virtual QSet<edb::address_t> specifiedFunctions() const { return {}; }
virtual Result<edb::address_t, QString> findContainingFunction(edb::address_t address) const = 0;
[[nodiscard]] virtual AddressCategory category(edb::address_t address) const = 0;
[[nodiscard]] virtual FunctionMap functions(const std::shared_ptr<IRegion> &region) const = 0;
[[nodiscard]] virtual FunctionMap functions() const = 0;
[[nodiscard]] virtual QSet<edb::address_t> specifiedFunctions() const { return {}; }
[[nodiscard]] virtual Result<edb::address_t, QString> findContainingFunction(edb::address_t address) const = 0;
virtual void analyze(const std::shared_ptr<IRegion> &region) = 0;
virtual void invalidateAnalysis() = 0;
virtual void invalidateAnalysis(const std::shared_ptr<IRegion> &region) = 0;
Expand Down
32 changes: 16 additions & 16 deletions include/IDebugEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ class IDebugEvent {

struct Message {
Message() = default;
Message(const QString &c, const QString &m, const QString &s)
: caption(c), message(m), statusMessage(s) {
Message(QString c, QString m, QString s)
: caption(std::move(c)), message(std::move(m)), statusMessage(std::move(s)) {
}

QString caption;
Expand All @@ -51,22 +51,22 @@ class IDebugEvent {
virtual ~IDebugEvent() = default;

public:
virtual IDebugEvent *clone() const = 0;
[[nodiscard]] virtual IDebugEvent *clone() const = 0;

public:
virtual Message errorDescription() const = 0;
virtual REASON reason() const = 0;
virtual TRAP_REASON trapReason() const = 0;
virtual bool exited() const = 0;
virtual bool isError() const = 0;
virtual bool isKill() const = 0;
virtual bool isStop() const = 0;
virtual bool isTrap() const = 0;
virtual bool stopped() const = 0;
virtual bool terminated() const = 0;
virtual edb::pid_t process() const = 0;
virtual edb::tid_t thread() const = 0;
virtual int64_t code() const = 0;
[[nodiscard]] virtual Message errorDescription() const = 0;
[[nodiscard]] virtual REASON reason() const = 0;
[[nodiscard]] virtual TRAP_REASON trapReason() const = 0;
[[nodiscard]] virtual bool exited() const = 0;
[[nodiscard]] virtual bool isError() const = 0;
[[nodiscard]] virtual bool isKill() const = 0;
[[nodiscard]] virtual bool isStop() const = 0;
[[nodiscard]] virtual bool isTrap() const = 0;
[[nodiscard]] virtual bool stopped() const = 0;
[[nodiscard]] virtual bool terminated() const = 0;
[[nodiscard]] virtual edb::pid_t process() const = 0;
[[nodiscard]] virtual edb::tid_t thread() const = 0;
[[nodiscard]] virtual int64_t code() const = 0;
};

#endif
2 changes: 1 addition & 1 deletion include/IDebugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class IDebugger {

public:
// basic process management
[[nodiscard]] virtual std::shared_ptr<IDebugEvent> waitDebugEvent(std::chrono::milliseconds msecs) = 0;
[[nodiscard]] virtual std::shared_ptr<IDebugEvent> waitDebugEvent(std::chrono::milliseconds msecs) = 0;
virtual Status attach(edb::pid_t pid) = 0;
virtual Status detach() = 0;
virtual Status open(const QString &path, const QString &cwd, const QList<QByteArray> &args, const QString &input, const QString &output) = 0;
Expand Down
2 changes: 1 addition & 1 deletion include/IProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class IProcess {
[[nodiscard]] virtual std::shared_ptr<IThread> currentThread() const = 0;
[[nodiscard]] virtual std::size_t readBytes(edb::address_t address, void *buf, size_t len) const = 0;
[[nodiscard]] virtual std::size_t readPages(edb::address_t address, void *buf, size_t count) const = 0;
[[nodiscard]] virtual QMap<edb::address_t, Patch> patches() const = 0;
[[nodiscard]] virtual QMap<edb::address_t, Patch> patches() const = 0;
virtual Status pause() = 0;
virtual Status resume(edb::EventStatus status) = 0;
virtual Status step(edb::EventStatus status) = 0;
Expand Down
20 changes: 10 additions & 10 deletions include/Value.h
Original file line number Diff line number Diff line change
Expand Up @@ -660,17 +660,17 @@ template <class T, class Integer, class = IsInteger<Integer>>

// operators for value_type, value_type
template <class T1, class T2>
[[nodiscard]]bool operator==(const value_type<T1> &lhs, const value_type<T2> &rhs) {
[[nodiscard]] bool operator==(const value_type<T1> &lhs, const value_type<T2> &rhs) {
return lhs.value_ == rhs.value_;
}

template <class T1, class T2>
[[nodiscard]]bool operator!=(const value_type<T1> &lhs, const value_type<T2> &rhs) {
[[nodiscard]] bool operator!=(const value_type<T1> &lhs, const value_type<T2> &rhs) {
return lhs.value_ != rhs.value_;
}

template <class T1, class T2>
[[nodiscard]]auto operator+(const value_type<T1> &lhs, const value_type<T2> &rhs) -> value_type<PromoteType<T1, T2>> {
[[nodiscard]] auto operator+(const value_type<T1> &lhs, const value_type<T2> &rhs) -> value_type<PromoteType<T1, T2>> {

using U = value_type<PromoteType<T1, T2>>;

Expand All @@ -680,7 +680,7 @@ template <class T1, class T2>
}

template <class T1, class T2>
[[nodiscard]]auto operator-(const value_type<T1> &lhs, const value_type<T2> &rhs) -> value_type<PromoteType<T1, T2>> {
[[nodiscard]] auto operator-(const value_type<T1> &lhs, const value_type<T2> &rhs) -> value_type<PromoteType<T1, T2>> {

using U = value_type<PromoteType<T1, T2>>;

Expand All @@ -690,7 +690,7 @@ template <class T1, class T2>
}

template <class T1, class T2>
[[nodiscard]]auto operator*(const value_type<T1> &lhs, const value_type<T2> &rhs) -> value_type<PromoteType<T1, T2>> {
[[nodiscard]] auto operator*(const value_type<T1> &lhs, const value_type<T2> &rhs) -> value_type<PromoteType<T1, T2>> {

using U = value_type<PromoteType<T1, T2>>;

Expand All @@ -700,7 +700,7 @@ template <class T1, class T2>
}

template <class T1, class T2>
[[nodiscard]]auto operator/(const value_type<T1> &lhs, const value_type<T2> &rhs) -> value_type<PromoteType<T1, T2>> {
[[nodiscard]] auto operator/(const value_type<T1> &lhs, const value_type<T2> &rhs) -> value_type<PromoteType<T1, T2>> {

using U = value_type<PromoteType<T1, T2>>;

Expand All @@ -710,7 +710,7 @@ template <class T1, class T2>
}

template <class T1, class T2>
[[nodiscard]]auto operator%(const value_type<T1> &lhs, const value_type<T2> &rhs) -> value_type<PromoteType<T1, T2>> {
[[nodiscard]] auto operator%(const value_type<T1> &lhs, const value_type<T2> &rhs) -> value_type<PromoteType<T1, T2>> {

using U = value_type<PromoteType<T1, T2>>;

Expand All @@ -720,7 +720,7 @@ template <class T1, class T2>
}

template <class T1, class T2>
[[nodiscard]]auto operator&(const value_type<T1> &lhs, const value_type<T2> &rhs) -> value_type<PromoteType<T1, T2>> {
[[nodiscard]] auto operator&(const value_type<T1> &lhs, const value_type<T2> &rhs) -> value_type<PromoteType<T1, T2>> {

using U = value_type<PromoteType<T1, T2>>;

Expand All @@ -730,7 +730,7 @@ template <class T1, class T2>
}

template <class T1, class T2>
[[nodiscard]]auto operator|(const value_type<T1> &lhs, const value_type<T2> &rhs) -> value_type<PromoteType<T1, T2>> {
[[nodiscard]] auto operator|(const value_type<T1> &lhs, const value_type<T2> &rhs) -> value_type<PromoteType<T1, T2>> {

using U = value_type<PromoteType<T1, T2>>;

Expand All @@ -740,7 +740,7 @@ template <class T1, class T2>
}

template <class T1, class T2>
[[nodiscard]]auto operator^(const value_type<T1> &lhs, const value_type<T2> &rhs) -> value_type<PromoteType<T1, T2>> {
[[nodiscard]] auto operator^(const value_type<T1> &lhs, const value_type<T2> &rhs) -> value_type<PromoteType<T1, T2>> {

using U = value_type<PromoteType<T1, T2>>;

Expand Down
4 changes: 2 additions & 2 deletions plugins/DebuggerCore/unix/Unix.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

#include "Unix.h"
#include <cstring>
#include <csignal>
#include <cstring>
#include <unistd.h>

namespace DebuggerCorePlugin {
Expand Down Expand Up @@ -209,7 +209,7 @@ Status Unix::execute_process(const QString &path, const QString &cwd, const QLis

p = argv_pointers;
while (*p) {
delete[] *p++;
delete[] * p++;
}
delete[] argv_pointers;
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/DebuggerCore/unix/freebsd/DebuggerCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <cerrno>
#include <cstring>

#include <csignal>
#include <fcntl.h>
#include <kvm.h>
#include <machine/reg.h>
#include <paths.h>
#include <csignal>
#include <sys/mman.h>
#include <sys/param.h>
#include <sys/ptrace.h>
Expand Down
2 changes: 1 addition & 1 deletion plugins/DebuggerCore/unix/freebsd/PlatformEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

#include "PlatformEvent.h"
#include "edb.h"
#include <csignal> // for the SIG* definitions
#include <cstdio>
#include <cstring>
#include <fcntl.h>
#include <kvm.h>
#include <csignal> // for the SIG* definitions
#include <sys/exec.h>
#include <sys/mman.h>
#include <sys/param.h>
Expand Down
2 changes: 1 addition & 1 deletion plugins/DebuggerCore/unix/freebsd/PlatformProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "PlatformProcess.h"
#include <csignal>
#include <fcntl.h>
#include <kvm.h>
#include <machine/reg.h>
#include <paths.h>
#include <csignal>
#include <sys/mman.h>
#include <sys/param.h>
#include <sys/ptrace.h>
Expand Down
4 changes: 3 additions & 1 deletion plugins/DebuggerCore/unix/linux/PlatformProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,9 @@ std::size_t PlatformProcess::writeBytes(edb::address_t address, const void *buf,
for (std::size_t byteIndex = 0; byteIndex < len; ++byteIndex) {
bool ok = false;
ptraceWriteByte(address + byteIndex, *(reinterpret_cast<const char *>(buf) + byteIndex), &ok);
if (!ok) return written;
if (!ok) {
return written;
}
++written;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,9 @@ Status PlatformThread::doStep(const edb::tid_t tid, const long status) {

State state;
getState(&state);
if (state.empty()) return Status(tr("failed to get thread state."));
if (state.empty()) {
return Status(tr("failed to get thread state."));
}
const auto pc = state.instructionPointer();
const auto flags = state.flags();
enum {
Expand Down Expand Up @@ -235,17 +237,24 @@ Status PlatformThread::doStep(const edb::tid_t tid, const long status) {
switch (op) {
case ARM_INS_LDR: {
const auto destOperand = insn.operand(0);
if (!is_register(destOperand) || destOperand->reg != ARM_REG_PC)
if (!is_register(destOperand) || destOperand->reg != ARM_REG_PC) {
return Status(tr("instruction %1 with non-PC destination isn't supported yet.").arg(insn.mnemonic().c_str()));
}

const auto srcOperand = insn.operand(1);
if (!is_expression(srcOperand))
if (!is_expression(srcOperand)) {
return Status(tr("unexpected type of second operand of LDR instruction."));
}

const auto effAddrR = edb::v1::arch_processor().getEffectiveAddress(insn, srcOperand, state);
if (!effAddrR) return Status(effAddrR.error());
if (!effAddrR) {
return Status(effAddrR.error());
}

const auto effAddr = effAddrR.value();
if (process_->readBytes(effAddr, &addrAfterInsn, AddressSize) != AddressSize)
if (process_->readBytes(effAddr, &addrAfterInsn, AddressSize) != AddressSize) {
return Status(tr("failed to read memory referred to by LDR operand (address %1).").arg(effAddr.toPointerString()));
}

// FIXME: for ARMv5 or below (without "T" in the name) bits [1:0] are simply ignored, without any mode change
if (addrAfterInsn & 1)
Expand Down Expand Up @@ -273,7 +282,9 @@ Status PlatformThread::doStep(const edb::tid_t tid, const long status) {
assert(operand->access == CS_AC_WRITE);
#endif
const auto sp = state.gpRegister(PlatformState::GPR::SP);
if (!sp) return Status(tr("failed to get value of SP register"));
if (!sp) {
return Status(tr("failed to get value of SP register"));
}
if (process_->readBytes(sp.valueAsAddress() + AddressSize * i, &addrAfterInsn, AddressSize) != AddressSize)
return Status(tr("failed to read thread stack"));
break;
Expand Down Expand Up @@ -305,7 +316,9 @@ Status PlatformThread::doStep(const edb::tid_t tid, const long status) {
return Status(tr("unpredictable instruction"));
// This may happen only with BX or BLX: B and BL require an immediate operand
const auto result = edb::v1::arch_processor().getEffectiveAddress(insn, operand, state);
if (!result) return Status(result.error());
if (!result) {
return Status(result.error());
}
addrAfterInsn = result.value();
if (addrAfterInsn & 1)
targetMode = IDebugger::CpuMode::Thumb;
Expand Down
2 changes: 1 addition & 1 deletion plugins/DebuggerCore/unix/openbsd/DebuggerCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <cerrno>
#include <cstring>

#include <csignal>
#include <fcntl.h>
#include <kvm.h>
#include <machine/reg.h>
#include <paths.h>
#include <csignal>
#include <sys/exec.h>
#include <sys/lock.h>
#include <sys/mman.h>
Expand Down
2 changes: 1 addition & 1 deletion plugins/DebuggerCore/unix/openbsd/PlatformEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

#include "PlatformEvent.h"
#include "edb.h"
#include <csignal> // for the SIG* definitions
#include <cstdio>
#include <cstring>
#include <fcntl.h>
#include <kvm.h>
#include <csignal> // for the SIG* definitions
#include <sys/exec.h>
#include <sys/mman.h>
#include <sys/param.h>
Expand Down
2 changes: 1 addition & 1 deletion plugins/DebuggerCore/unix/osx/DebuggerCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

#include <QDebug>

#include <csignal>
#include <fcntl.h>
#include <mach/mach.h>
#include <mach/mach_vm.h>
#include <mach/vm_region.h>
#include <mach/vm_statistics.h>
#include <paths.h>
#include <csignal>
#include <sys/mman.h>
#include <sys/param.h>
#include <sys/proc.h>
Expand Down
2 changes: 1 addition & 1 deletion plugins/DebuggerCore/unix/osx/PlatformEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

#include "PlatformEvent.h"
#include "edb.h"
#include <csignal> // for the SIG* definitions
#include <cstdio>
#include <cstring>
#include <csignal> // for the SIG* definitions
#include <sys/ptrace.h>
#include <sys/types.h>
#include <sys/wait.h>
Expand Down
12 changes: 9 additions & 3 deletions src/arch/arm-generic/ArchProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,13 @@ Result<edb::address_t, QString> ArchProcessor::getEffectiveAddress(const edb::In
if (is_register(operand)) {
bool ok;
const auto regIndex = capstoneRegToGPRIndex(operand->reg, ok);
if (!ok) return make_unexpected(QObject::tr("bad operand register for instruction %1: %2.").arg(insn.mnemonic().c_str()).arg(operand->reg));
if (!ok) {
return make_unexpected(QObject::tr("bad operand register for instruction %1: %2.").arg(insn.mnemonic().c_str()).arg(operand->reg));
}
const auto reg = state.gpRegister(regIndex);
if (!reg) return make_unexpected(QObject::tr("failed to get register r%1.").arg(regIndex));
if (!reg) {
return make_unexpected(QObject::tr("failed to get register r%1.").arg(regIndex));
}
auto value = reg.valueAsAddress();
return adjustR15Value(insn, regIndex, value);
} else if (is_expression(operand)) {
Expand Down Expand Up @@ -226,7 +230,9 @@ edb::address_t ArchProcessor::getEffectiveAddress(const edb::Instruction &inst,

ok = false;
const auto result = getEffectiveAddress(inst, op, state);
if (!result) return 0;
if (!result) {
return 0;
}
return result.value();
}

Expand Down
Loading

0 comments on commit c137554

Please sign in to comment.