From 9c097ca3dc4d7e1769a27ca324ed5a34c60e905f Mon Sep 17 00:00:00 2001 From: Evan Teran Date: Mon, 18 Mar 2024 14:53:01 -0400 Subject: [PATCH] a bunch more annotations --- cspell.config.yaml | 1 + include/Expression.h | 2 +- include/IState.h | 56 ++++---- include/MemoryRegions.h | 12 +- include/Register.h | 10 +- include/RegisterRef.h | 6 +- include/RegisterViewModelBase.h | 170 +++++++++++++------------ include/Status.h | 32 ++--- include/Symbol.h | 6 +- include/Value.h | 134 +++++++++---------- plugins/BinaryInfo/ELFXX.cpp | 10 +- plugins/BinaryInfo/ELFXX.h | 10 +- plugins/BinaryInfo/PE32.h | 12 +- plugins/BinaryInfo/symbols.cpp | 16 +-- plugins/DumpState/DumpState.cpp | 24 ++-- src/FixedFontSelector.cpp | 2 +- src/FixedFontSelector.h | 2 +- src/capstone-edb/include/Instruction.h | 2 +- src/capstone-edb/include/Operand.h | 2 +- 19 files changed, 260 insertions(+), 249 deletions(-) diff --git a/cspell.config.yaml b/cspell.config.yaml index 7643c0c07..50f1d0276 100644 --- a/cspell.config.yaml +++ b/cspell.config.yaml @@ -22,6 +22,7 @@ words: - konsole - Mercês - METATYPE + - Midlight - Mohd - nasm - Nicoleau diff --git a/include/Expression.h b/include/Expression.h index 83abd69b9..21392354a 100644 --- a/include/Expression.h +++ b/include/Expression.h @@ -46,7 +46,7 @@ struct ExpressionError { : error_(type) { } - const char *what() const noexcept { + [[nodiscard]] const char *what() const noexcept { switch (error_) { case Syntax: return "Syntax Error"; diff --git a/include/IState.h b/include/IState.h index 38ca82805..c38f4d4f3 100644 --- a/include/IState.h +++ b/include/IState.h @@ -31,31 +31,31 @@ class IState { virtual ~IState() = default; public: - virtual std::unique_ptr clone() const = 0; + [[nodiscard]] virtual std::unique_ptr clone() const = 0; public: - virtual QString flagsToString() const = 0; - virtual QString flagsToString(edb::reg_t flags) const = 0; - virtual Register value(const QString ®) const = 0; - virtual Register instructionPointerRegister() const = 0; - virtual Register flagsRegister() const = 0; - virtual edb::address_t framePointer() const = 0; - virtual edb::address_t instructionPointer() const = 0; - virtual edb::address_t stackPointer() const = 0; - virtual edb::reg_t debugRegister(size_t n) const = 0; - virtual edb::reg_t flags() const = 0; - virtual void adjustStack(int bytes) = 0; - virtual void clear() = 0; - virtual bool empty() const = 0; - virtual void setDebugRegister(size_t n, edb::reg_t value) = 0; - virtual void setFlags(edb::reg_t flags) = 0; - virtual void setInstructionPointer(edb::address_t value) = 0; - virtual void setRegister(const QString &name, edb::reg_t value) = 0; - virtual void setRegister(const Register ®) = 0; + [[nodiscard]] virtual bool empty() const = 0; + [[nodiscard]] virtual edb::address_t framePointer() const = 0; + [[nodiscard]] virtual edb::address_t instructionPointer() const = 0; + [[nodiscard]] virtual edb::address_t stackPointer() const = 0; + [[nodiscard]] virtual edb::reg_t debugRegister(size_t n) const = 0; + [[nodiscard]] virtual edb::reg_t flags() const = 0; + [[nodiscard]] virtual QString flagsToString() const = 0; + [[nodiscard]] virtual QString flagsToString(edb::reg_t flags) const = 0; + [[nodiscard]] virtual Register flagsRegister() const = 0; + [[nodiscard]] virtual Register instructionPointerRegister() const = 0; + [[nodiscard]] virtual Register value(const QString ®) const = 0; + virtual void adjustStack(int bytes) = 0; + virtual void clear() = 0; + virtual void setDebugRegister(size_t n, edb::reg_t value) = 0; + virtual void setFlags(edb::reg_t flags) = 0; + virtual void setInstructionPointer(edb::address_t value) = 0; + virtual void setRegister(const QString &name, edb::reg_t value) = 0; + virtual void setRegister(const Register ®) = 0; public: // GP - virtual Register gpRegister(size_t n) const = 0; + [[nodiscard]] virtual Register gpRegister(size_t n) const = 0; public: // This is a more generic means to request architecture @@ -63,18 +63,18 @@ class IState { // edb::string_hash, for example: // edb::string_hash("mmx"), string_hash("xmm"), and string_hash("ymm") // This will allow this interface to be much more platform independent - virtual Register archRegister(uint64_t type, size_t n) const = 0; + [[nodiscard]] virtual Register archRegister(uint64_t type, size_t n) const = 0; #if defined(EDB_X86) || defined(EDB_X86_64) public: // FPU - virtual int fpuStackPointer() const = 0; - virtual bool fpuRegisterIsEmpty(std::size_t n) const = 0; - virtual edb::value80 fpuRegister(size_t n) const = 0; - virtual QString fpuRegisterTagString(std::size_t n) const = 0; - virtual edb::value16 fpuControlWord() const = 0; - virtual edb::value16 fpuStatusWord() const = 0; - virtual edb::value16 fpuTagWord() const = 0; + [[nodiscard]] virtual int fpuStackPointer() const = 0; + [[nodiscard]] virtual bool fpuRegisterIsEmpty(std::size_t n) const = 0; + [[nodiscard]] virtual edb::value80 fpuRegister(size_t n) const = 0; + [[nodiscard]] virtual QString fpuRegisterTagString(std::size_t n) const = 0; + [[nodiscard]] virtual edb::value16 fpuControlWord() const = 0; + [[nodiscard]] virtual edb::value16 fpuStatusWord() const = 0; + [[nodiscard]] virtual edb::value16 fpuTagWord() const = 0; #endif }; diff --git a/include/MemoryRegions.h b/include/MemoryRegions.h index 4695bd92f..43e7eca0f 100644 --- a/include/MemoryRegions.h +++ b/include/MemoryRegions.h @@ -31,12 +31,12 @@ class EDB_EXPORT MemoryRegions final : public QAbstractItemModel { Q_OBJECT public: - QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; - QModelIndex parent(const QModelIndex &index) const override; - QVariant data(const QModelIndex &index, int role) const override; - QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; - int columnCount(const QModelIndex &parent = QModelIndex()) const override; - int rowCount(const QModelIndex &parent = QModelIndex()) const override; + [[nodiscard]] QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; + [[nodiscard]] QModelIndex parent(const QModelIndex &index) const override; + [[nodiscard]] QVariant data(const QModelIndex &index, int role) const override; + [[nodiscard]] QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; + [[nodiscard]] int columnCount(const QModelIndex &parent = QModelIndex()) const override; + [[nodiscard]] int rowCount(const QModelIndex &parent = QModelIndex()) const override; public: MemoryRegions(); diff --git a/include/Register.h b/include/Register.h index e4c99291e..83e4699da 100644 --- a/include/Register.h +++ b/include/Register.h @@ -56,8 +56,8 @@ class EDB_EXPORT Register { [[nodiscard]] bool operator!=(const Register &rhs) const; public: - bool valid() const { return type_ != TYPE_INVALID; } - explicit operator bool() const { return valid(); } + [[nodiscard]] bool valid() const { return type_ != TYPE_INVALID; } + [[nodiscard]] explicit operator bool() const { return valid(); } [[nodiscard]] Type type() const { return type_; } [[nodiscard]] QString name() const { return name_; } @@ -65,16 +65,16 @@ class EDB_EXPORT Register { [[nodiscard]] const char *rawData() const { return reinterpret_cast(&value_); } template - T value() const { return T(value_); } + [[nodiscard]] T value() const { return T(value_); } // Return the value, zero-extended to address_t to be usable in address calculations [[nodiscard]] edb::address_t valueAsAddress() const; - uint64_t valueAsInteger() const { + [[nodiscard]] uint64_t valueAsInteger() const { return valueAsAddress().toUint(); } - int64_t valueAsSignedInteger() const { + [[nodiscard]] int64_t valueAsSignedInteger() const { uint64_t result = valueAsInteger(); // If MSB is set, sign extend the result if (result & (1ll << (bitSize_ - 1))) { diff --git a/include/RegisterRef.h b/include/RegisterRef.h index 675f2b6dd..b2532c951 100644 --- a/include/RegisterRef.h +++ b/include/RegisterRef.h @@ -24,11 +24,11 @@ class RegisterRef { const void *data() const { return ptr_; } public: - bool operator==(const RegisterRef &rhs) const { return size_ == rhs.size_ && std::memcmp(ptr_, rhs.ptr_, size_) == 0; } - bool operator!=(const RegisterRef &rhs) const { return size_ != rhs.size_ || std::memcmp(ptr_, rhs.ptr_, size_) != 0; } + [[nodiscard]] bool operator==(const RegisterRef &rhs) const { return size_ == rhs.size_ && std::memcmp(ptr_, rhs.ptr_, size_) == 0; } + [[nodiscard]] bool operator!=(const RegisterRef &rhs) const { return size_ != rhs.size_ || std::memcmp(ptr_, rhs.ptr_, size_) != 0; } public: - bool valid() const { return ptr_ != nullptr; } + [[nodiscard]] bool valid() const { return ptr_ != nullptr; } public: // The name of this register. diff --git a/include/RegisterViewModelBase.h b/include/RegisterViewModelBase.h index fad805101..f87732a85 100644 --- a/include/RegisterViewModelBase.h +++ b/include/RegisterViewModelBase.h @@ -126,13 +126,13 @@ class EDB_EXPORT Model : public QAbstractItemModel { ~Model() override = default; public: - int rowCount(const QModelIndex &parent = QModelIndex()) const override; - int columnCount(const QModelIndex &parent = QModelIndex()) const override; - QModelIndex parent(const QModelIndex &index) const override; - QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; - QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; + [[nodiscard]] int columnCount(const QModelIndex &parent = QModelIndex()) const override; + [[nodiscard]] int rowCount(const QModelIndex &parent = QModelIndex()) const override; + [[nodiscard]] QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; + [[nodiscard]] QModelIndex parent(const QModelIndex &index) const override; + [[nodiscard]] Qt::ItemFlags flags(const QModelIndex &index) const override; + [[nodiscard]] QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; bool setData(const QModelIndex &index, const QVariant &data, int role = Qt::EditRole) override; - Qt::ItemFlags flags(const QModelIndex &index) const override; public: void setActiveIndex(const QModelIndex &newActiveIndex); @@ -189,36 +189,36 @@ class RegisterViewItem { public: void init(RegisterViewItem *parent, int row); - virtual RegisterViewItem *parent() const { + [[nodiscard]] virtual RegisterViewItem *parent() const { return parentItem; } - QString name() const { + [[nodiscard]] QString name() const { return name_; } - virtual int row() const { + [[nodiscard]] virtual int row() const { Q_ASSERT(row_ != -1); return row_; } - virtual bool changed() const { + [[nodiscard]] virtual bool changed() const { return false; } - virtual RegisterViewItem *child(int /*row*/) { + [[nodiscard]] virtual RegisterViewItem *child(int /*row*/) { return nullptr; } - virtual int childCount() const { + [[nodiscard]] virtual int childCount() const { return 0; } - virtual QVariant data(int /*column*/) const { + [[nodiscard]] virtual QVariant data(int /*column*/) const { return QVariant(); } - virtual int valueMaxLength() const { + [[nodiscard]] virtual int valueMaxLength() const { return 0; } @@ -234,7 +234,7 @@ class AbstractRegisterItem : public RegisterViewItem { public: // check whether it has some valid value (not unknown etc.) - virtual bool valid() const = 0; + [[nodiscard]] virtual bool valid() const = 0; // Should be used when EDB is about to resume execution of debuggee — // so that it's possible to check whether it changed on next stop virtual void saveValue() = 0; @@ -259,17 +259,19 @@ class RegisterItem : public AbstractRegisterItem { public: RegisterItem(const QString &name); - bool valid() const override; - void saveValue() override; - bool changed() const override; - void invalidate() override; - int childCount() const override; - RegisterViewItem *child(int) override; - QVariant data(int column) const override; - QByteArray rawValue() const override; - bool setValue(const QString &valueStr) override; + +public: + [[nodiscard]] bool changed() const override; + [[nodiscard]] bool valid() const override; + [[nodiscard]] int childCount() const override; + [[nodiscard]] QByteArray rawValue() const override; + [[nodiscard]] QVariant data(int column) const override; + [[nodiscard]] RegisterViewItem *child(int) override; bool setValue(const QByteArray &value) override; + bool setValue(const QString &valueStr) override; bool setValue(const Register ®) override; + void invalidate() override; + void saveValue() override; }; template @@ -281,7 +283,7 @@ class SimpleRegister : public RegisterItem { public: virtual void update(const StoredType &newValue, const QString &newComment); - int valueMaxLength() const override; + [[nodiscard]] int valueMaxLength() const override; }; struct BitFieldDescriptionEx { @@ -298,9 +300,9 @@ struct BitFieldDescriptionEx { class BitFieldProperties { public: - virtual ~BitFieldProperties() = default; - virtual unsigned offset() const = 0; - virtual unsigned length() const = 0; + virtual ~BitFieldProperties() = default; + [[nodiscard]] virtual unsigned offset() const = 0; + [[nodiscard]] virtual unsigned length() const = 0; }; template @@ -314,23 +316,23 @@ class BitFieldItem final : public RegisterViewItem, public BitFieldProperties { std::vector explanations; protected: - FlagsRegister *reg() const; - UnderlyingType lengthToMask() const; - UnderlyingType calcValue(UnderlyingType regVal) const; - UnderlyingType value() const; - UnderlyingType prevValue() const; + [[nodiscard]] FlagsRegister *reg() const; + [[nodiscard]] UnderlyingType lengthToMask() const; + [[nodiscard]] UnderlyingType calcValue(UnderlyingType regVal) const; + [[nodiscard]] UnderlyingType value() const; + [[nodiscard]] UnderlyingType prevValue() const; public: BitFieldItem(const BitFieldDescriptionEx &descr); public: - QVariant data(int column) const override; - bool changed() const override; - int valueMaxLength() const override; - QByteArray rawValue() const override; + [[nodiscard]] QVariant data(int column) const override; + [[nodiscard]] bool changed() const override; + [[nodiscard]] int valueMaxLength() const override; + [[nodiscard]] QByteArray rawValue() const override; - unsigned offset() const override; - unsigned length() const override; + [[nodiscard]] unsigned offset() const override; + [[nodiscard]] unsigned length() const override; }; template @@ -342,8 +344,8 @@ class FlagsRegister final : public SimpleRegister { FlagsRegister(const QString &name, const std::vector &bitFields); public: - RegisterViewItem *child(int) override; - int childCount() const override; + [[nodiscard]] RegisterViewItem *child(int) override; + [[nodiscard]] int childCount() const override; protected: std::vector> fields; @@ -361,14 +363,14 @@ class SIMDFormatItem final : public RegisterViewItem { using RegisterViewItem::name; public: - NumberDisplayMode format() const; - QByteArray rawValue() const override; - QVariant data(int column) const override; - bool changed() const override; - int valueMaxLength() const override; + [[nodiscard]] NumberDisplayMode format() const; + [[nodiscard]] QByteArray rawValue() const override; + [[nodiscard]] QVariant data(int column) const override; + [[nodiscard]] bool changed() const override; + [[nodiscard]] int valueMaxLength() const override; private: - QString name(NumberDisplayMode format) const; + [[nodiscard]] QString name(NumberDisplayMode format) const; private: NumberDisplayMode format_; @@ -384,18 +386,18 @@ class SIMDSizedElement final : public RegisterViewItem, public SIMDElement { SIMDSizedElement(const QString &name, const std::vector &validFormats); public: - QByteArray rawValue() const override; - QVariant data(int column) const override; - RegisterViewItem *child(int row) override; - bool changed() const override; - int childCount() const override; - int valueMaxLength() const override; + [[nodiscard]] QByteArray rawValue() const override; + [[nodiscard]] QVariant data(int column) const override; + [[nodiscard]] RegisterViewItem *child(int row) override; + [[nodiscard]] bool changed() const override; + [[nodiscard]] int childCount() const override; + [[nodiscard]] int valueMaxLength() const override; private: - QString valueString() const; - SIMDRegister *reg() const; - SizingType value() const; - bool valid() const; + [[nodiscard]] QString valueString() const; + [[nodiscard]] SIMDRegister *reg() const; + [[nodiscard]] SizingType value() const; + [[nodiscard]] bool valid() const; private: std::vector> formats; @@ -412,11 +414,13 @@ class SIMDSizedElementsContainer final : public RegisterViewItem { public: SIMDSizedElementsContainer(const QString &name, std::size_t size, const std::vector &validFormats); SIMDSizedElementsContainer(SIMDSizedElementsContainer &&other) noexcept; - RegisterViewItem *child(int row) override; - int childCount() const override; - QVariant data(int column) const override; - QByteArray rawValue() const override; - bool changed() const override; + +public: + [[nodiscard]] RegisterViewItem *child(int row) override; + [[nodiscard]] int childCount() const override; + [[nodiscard]] QVariant data(int column) const override; + [[nodiscard]] QByteArray rawValue() const override; + [[nodiscard]] bool changed() const override; }; template @@ -431,9 +435,11 @@ class SIMDRegister final : public SimpleRegister { public: SIMDRegister(const QString &name, const std::vector &validFormats); - int childCount() const override; - RegisterViewItem *child(int) override; - QVariant data(int column) const override; + +public: + [[nodiscard]] int childCount() const override; + [[nodiscard]] RegisterViewItem *child(int) override; + [[nodiscard]] QVariant data(int column) const override; }; class GenericFPURegister {}; // generic non-templated class to dynamic_cast to @@ -447,10 +453,10 @@ class FPURegister final : public SimpleRegister, public GenericFPUReg FPURegister(const QString &name); public: - QString valueString() const override; - RegisterViewItem *child(int) override; - int childCount() const override; - int valueMaxLength() const override; + [[nodiscard]] QString valueString() const override; + [[nodiscard]] RegisterViewItem *child(int) override; + [[nodiscard]] int childCount() const override; + [[nodiscard]] int valueMaxLength() const override; void saveValue() override; void update(const FloatType &newValue, const QString &newComment) override; @@ -470,12 +476,12 @@ class Category : public RegisterViewItem { Category(Category &&other) noexcept; public: - AbstractRegisterItem *getRegister(std::size_t i) const; - QByteArray rawValue() const override; - QVariant data(int column) const override; - RegisterViewItem *child(int row) override; - bool visible() const; - int childCount() const override; + [[nodiscard]] AbstractRegisterItem *getRegister(std::size_t i) const; + [[nodiscard]] QByteArray rawValue() const override; + [[nodiscard]] QVariant data(int column) const override; + [[nodiscard]] RegisterViewItem *child(int row) override; + [[nodiscard]] bool visible() const; + [[nodiscard]] int childCount() const override; void addRegister(std::unique_ptr reg); void hide(); void saveValues(); @@ -492,8 +498,8 @@ class SIMDCategory final : public Category { ~SIMDCategory(); public: - virtual Model::ElementSize chosenSize() const; - virtual NumberDisplayMode chosenFormat() const; + [[nodiscard]] virtual Model::ElementSize chosenSize() const; + [[nodiscard]] virtual NumberDisplayMode chosenFormat() const; virtual void setChosenSize(Model::ElementSize newSize); virtual void setChosenFormat(NumberDisplayMode newFormat); @@ -532,11 +538,11 @@ class CategoriesHolder final : public RegisterViewItem { template CategoryType *insert(const QString &name); - SIMDCategory *insertSimd(const QString &name, const std::vector &validFormats); - int childCount() const override; - RegisterViewItem *child(int row) override; - QVariant data(int column) const override; - QByteArray rawValue() const override; + [[nodiscard]] SIMDCategory *insertSimd(const QString &name, const std::vector &validFormats); + [[nodiscard]] int childCount() const override; + [[nodiscard]] RegisterViewItem *child(int row) override; + [[nodiscard]] QVariant data(int column) const override; + [[nodiscard]] QByteArray rawValue() const override; private: std::vector> categories; diff --git a/include/Status.h b/include/Status.h index f77024154..c5e24c00a 100644 --- a/include/Status.h +++ b/include/Status.h @@ -42,10 +42,10 @@ class EDB_EXPORT Status { Status &operator=(Status &&) = default; public: - bool success() const { return error_.isEmpty(); } - bool failure() const { return !success(); } - explicit operator bool() const { return success(); } - QString error() const { return error_; } + [[nodiscard]] bool failure() const { return !success(); } + [[nodiscard]] bool success() const { return error_.isEmpty(); } + [[nodiscard]] QString error() const { return error_; } + [[nodiscard]] explicit operator bool() const { return success(); } private: QString error_; @@ -105,18 +105,18 @@ class Result { return &std::get(value_); } - const T &operator*() const { return value(); } - bool succeeded() const { return value_.index() == 0; } - bool failed() const { return value_.index() == 1; } - explicit operator bool() const { return succeeded(); } - bool operator!() const { return failed(); } + [[nodiscard]] bool failed() const { return value_.index() == 1; } + [[nodiscard]] bool operator!() const { return failed(); } + [[nodiscard]] bool succeeded() const { return value_.index() == 0; } + [[nodiscard]] const T &operator*() const { return value(); } + [[nodiscard]] explicit operator bool() const { return succeeded(); } - const E &error() const { + [[nodiscard]] const E &error() const { Q_ASSERT(failed()); return std::get>(value_).error_; } - const T &value() const { + [[nodiscard]] const T &value() const { Q_ASSERT(succeeded()); return std::get(value_); } @@ -144,12 +144,12 @@ class Result { Result &operator=(Result &&) = default; public: - bool succeeded() const { return value_.index() == 0; } - bool failed() const { return value_.index() == 1; } - explicit operator bool() const { return succeeded(); } - bool operator!() const { return failed(); } + [[nodiscard]] bool failed() const { return value_.index() == 1; } + [[nodiscard]] bool operator!() const { return failed(); } + [[nodiscard]] bool succeeded() const { return value_.index() == 0; } + [[nodiscard]] explicit operator bool() const { return succeeded(); } - const E &error() const { + [[nodiscard]] const E &error() const { Q_ASSERT(failed()); return std::get>(value_).error_; } diff --git a/include/Symbol.h b/include/Symbol.h index 8443fe4de..a8b5f1361 100644 --- a/include/Symbol.h +++ b/include/Symbol.h @@ -33,9 +33,9 @@ class Symbol { uint32_t size; char type; - bool isCode() const { return type == 't' || type == 'T' || type == 'P'; } - bool isData() const { return !isCode(); } - bool isWeak() const { return type == 'W'; } + [[nodiscard]] bool isCode() const { return type == 't' || type == 'T' || type == 'P'; } + [[nodiscard]] bool isData() const { return !isCode(); } + [[nodiscard]] bool isWeak() const { return type == 'W'; } }; #endif diff --git a/include/Value.h b/include/Value.h index 51d2d0456..c7f634bc0 100644 --- a/include/Value.h +++ b/include/Value.h @@ -70,11 +70,11 @@ class value_type_large { } public: - bool operator==(const value_type_large &rhs) const { return std::memcmp(value_, rhs.value_, sizeof(T)) == 0; } - bool operator!=(const value_type_large &rhs) const { return std::memcmp(value_, rhs.value_, sizeof(T)) != 0; } + [[nodiscard]] bool operator==(const value_type_large &rhs) const { return std::memcmp(value_, rhs.value_, sizeof(T)) == 0; } + [[nodiscard]] bool operator!=(const value_type_large &rhs) const { return std::memcmp(value_, rhs.value_, sizeof(T)) != 0; } public: - QString toHexString() const { + [[nodiscard]] QString toHexString() const { char buf[sizeof(T) * 2 + 1]; char *p = buf; @@ -87,7 +87,7 @@ class value_type_large { public: template - static value_type_large fromZeroExtended(const U &data) { + [[nodiscard]] static value_type_large fromZeroExtended(const U &data) { static_assert(sizeof(data) <= sizeof(T), "It doesn't make sense to expand a larger type into a smaller type"); @@ -172,7 +172,7 @@ class value_type { } public: - static value_type fromString(const QString &str, bool *ok = nullptr, int base = 10, bool isSigned = false) { + [[nodiscard]] static value_type fromString(const QString &str, bool *ok = nullptr, int base = 10, bool isSigned = false) { const qulonglong v = isSigned ? static_cast(str.toLongLong(ok, base)) : str.toULongLong(ok, base); @@ -193,20 +193,20 @@ class value_type { return 0; } - static value_type fromHexString(const QString &str, bool *ok = nullptr) { + [[nodiscard]] static value_type fromHexString(const QString &str, bool *ok = nullptr) { return fromString(str, ok, 16); } - static value_type fromSignedString(const QString &str, bool *ok = nullptr) { + [[nodiscard]] static value_type fromSignedString(const QString &str, bool *ok = nullptr) { return fromString(str, ok, 10, true); } - static value_type fromCString(const QString &str, bool *ok = nullptr) { + [[nodiscard]] static value_type fromCString(const QString &str, bool *ok = nullptr) { return fromString(str, ok, 0); } template - static value_type fromZeroExtended(const U &data) { + [[nodiscard]] static value_type fromZeroExtended(const U &data) { value_type created; static_assert(sizeof(data) <= sizeof(T), "It doesn't make sense to expand a larger type into a smaller type"); @@ -227,16 +227,16 @@ class value_type { } public: - bool negative() const { + [[nodiscard]] bool negative() const { return typename std::make_signed::type(value_) < 0; } public: - explicit operator bool() const { return value_ != 0; } + [[nodiscard]] explicit operator bool() const { return value_ != 0; } bool operator!() const { return !value_; } operator T() const { return value_; } - T toUint() const { return value_; } - T &asUint() { return value_; } + [[nodiscard]] T toUint() const { return value_; } + [[nodiscard]] T &asUint() { return value_; } public: value_type operator++(int) { @@ -386,37 +386,37 @@ class value_type { } public: - QString toPointerString(bool createdFromNativePointer = true) const { + [[nodiscard]] QString toPointerString(bool createdFromNativePointer = true) const { if (edb::v1::debuggeeIs32Bit()) { return "0x" + value_type(value_).toHexString(); - } else { - if (!createdFromNativePointer) { // then we don't know value of upper dword - return "0x????????" + value_type(value_).toHexString(); - } else { - return "0x" + toHexString(); - } } + + if (!createdFromNativePointer) { // then we don't know value of upper dword + return "0x????????" + value_type(value_).toHexString(); + } + + return "0x" + toHexString(); } - QString toHexString() const { + [[nodiscard]] QString toHexString() const { std::ostringstream ss; ss << std::setw(sizeof(value_) * 2) << std::setfill('0') << std::hex << +value_; // + to prevent printing uint8_t as a character return QString::fromStdString(ss.str()); } - QString unsignedToString() const { + [[nodiscard]] QString unsignedToString() const { return toString(); } - QString signedToString() const { + [[nodiscard]] QString signedToString() const { return QString("%1").arg(typename std::make_signed::type(value_)); } - QString toString() const { + [[nodiscard]] QString toString() const { return QString("%1").arg(value_); } - QVariant toQVariant() const { + [[nodiscard]] QVariant toQVariant() const { return QVariant::fromValue(value_); } @@ -466,82 +466,82 @@ std::ostream &operator<<(std::ostream &os, value_type &val) { // operators for value_type, Integer template > -bool operator==(const value_type &lhs, Integer rhs) { +[[nodiscard]] bool operator==(const value_type &lhs, Integer rhs) { using U = typename std::make_unsigned::type; return lhs.value_ == static_cast(rhs); } template > -bool operator!=(const value_type &lhs, Integer rhs) { +[[nodiscard]] bool operator!=(const value_type &lhs, Integer rhs) { using U = typename std::make_unsigned::type; return lhs.value_ != static_cast(rhs); } template > -auto operator+(const value_type &lhs, Integer rhs) -> value_type { +[[nodiscard]] auto operator+(const value_type &lhs, Integer rhs) -> value_type { value_type r(lhs); r += rhs; return r; } template > -auto operator-(const value_type &lhs, Integer rhs) -> value_type { +[[nodiscard]] auto operator-(const value_type &lhs, Integer rhs) -> value_type { value_type r(lhs); r -= rhs; return r; } template > -auto operator*(const value_type &lhs, Integer rhs) -> value_type { +[[nodiscard]] auto operator*(const value_type &lhs, Integer rhs) -> value_type { value_type r(lhs); r *= rhs; return r; } template > -auto operator/(const value_type &lhs, Integer rhs) -> value_type { +[[nodiscard]] auto operator/(const value_type &lhs, Integer rhs) -> value_type { value_type r(lhs); r /= rhs; return r; } template > -auto operator%(const value_type &lhs, Integer rhs) -> value_type { +[[nodiscard]] auto operator%(const value_type &lhs, Integer rhs) -> value_type { value_type r(lhs); r %= rhs; return r; } template > -auto operator&(const value_type &lhs, Integer rhs) -> value_type { +[[nodiscard]] auto operator&(const value_type &lhs, Integer rhs) -> value_type { value_type r(lhs); r &= rhs; return r; } template > -auto operator|(const value_type &lhs, Integer rhs) -> value_type { +[[nodiscard]] auto operator|(const value_type &lhs, Integer rhs) -> value_type { value_type r(lhs); r |= rhs; return r; } template > -auto operator^(const value_type &lhs, Integer rhs) -> value_type { +[[nodiscard]] auto operator^(const value_type &lhs, Integer rhs) -> value_type { value_type r(lhs); r ^= rhs; return r; } template > -auto operator>>(const value_type &lhs, Integer rhs) -> value_type { +[[nodiscard]] auto operator>>(const value_type &lhs, Integer rhs) -> value_type { value_type r(lhs); r >>= rhs; return r; } template > -auto operator<<(const value_type &lhs, Integer rhs) -> value_type { +[[nodiscard]] auto operator<<(const value_type &lhs, Integer rhs) -> value_type { value_type r(lhs); r <<= rhs; return r; @@ -549,17 +549,17 @@ auto operator<<(const value_type &lhs, Integer rhs) -> value_type { // operators for Integer, value_type template > -bool operator==(Integer lhs, const value_type &rhs) { +[[nodiscard]] bool operator==(Integer lhs, const value_type &rhs) { return rhs == lhs; } template > -bool operator!=(Integer lhs, const value_type &rhs) { +[[nodiscard]] bool operator!=(Integer lhs, const value_type &rhs) { return rhs != lhs; } template > -auto operator+(Integer lhs, const value_type &rhs) -> value_type> { +[[nodiscard]] auto operator+(Integer lhs, const value_type &rhs) -> value_type> { using U = value_type>; @@ -569,7 +569,7 @@ auto operator+(Integer lhs, const value_type &rhs) -> value_type> -auto operator-(Integer lhs, const value_type &rhs) -> value_type> { +[[nodiscard]] auto operator-(Integer lhs, const value_type &rhs) -> value_type> { using U = value_type>; @@ -579,7 +579,7 @@ auto operator-(Integer lhs, const value_type &rhs) -> value_type> -auto operator*(Integer lhs, const value_type &rhs) -> value_type> { +[[nodiscard]] auto operator*(Integer lhs, const value_type &rhs) -> value_type> { using U = value_type>; @@ -589,7 +589,7 @@ auto operator*(Integer lhs, const value_type &rhs) -> value_type> -auto operator/(Integer lhs, const value_type &rhs) -> value_type> { +[[nodiscard]] auto operator/(Integer lhs, const value_type &rhs) -> value_type> { using U = value_type>; @@ -599,7 +599,7 @@ auto operator/(Integer lhs, const value_type &rhs) -> value_type> -auto operator%(Integer lhs, const value_type &rhs) -> value_type> { +[[nodiscard]] auto operator%(Integer lhs, const value_type &rhs) -> value_type> { using U = value_type>; @@ -609,7 +609,7 @@ auto operator%(Integer lhs, const value_type &rhs) -> value_type> -auto operator&(Integer lhs, const value_type &rhs) -> value_type> { +[[nodiscard]] auto operator&(Integer lhs, const value_type &rhs) -> value_type> { using U = value_type>; @@ -619,7 +619,7 @@ auto operator&(Integer lhs, const value_type &rhs) -> value_type> -auto operator|(Integer lhs, const value_type &rhs) -> value_type> { +[[nodiscard]] auto operator|(Integer lhs, const value_type &rhs) -> value_type> { using U = value_type>; @@ -629,7 +629,7 @@ auto operator|(Integer lhs, const value_type &rhs) -> value_type> -auto operator^(Integer lhs, const value_type &rhs) -> value_type> { +[[nodiscard]] auto operator^(Integer lhs, const value_type &rhs) -> value_type> { using U = value_type>; @@ -639,7 +639,7 @@ auto operator^(Integer lhs, const value_type &rhs) -> value_type> -auto operator>>(Integer lhs, const value_type &rhs) -> value_type> { +[[nodiscard]] auto operator>>(Integer lhs, const value_type &rhs) -> value_type> { using U = value_type>; @@ -649,7 +649,7 @@ auto operator>>(Integer lhs, const value_type &rhs) -> value_type> -auto operator<<(Integer lhs, const value_type &rhs) -> value_type> { +[[nodiscard]] auto operator<<(Integer lhs, const value_type &rhs) -> value_type> { using U = value_type>; @@ -660,17 +660,17 @@ auto operator<<(Integer lhs, const value_type &rhs) -> value_type -bool operator==(const value_type &lhs, const value_type &rhs) { +[[nodiscard]]bool operator==(const value_type &lhs, const value_type &rhs) { return lhs.value_ == rhs.value_; } template -bool operator!=(const value_type &lhs, const value_type &rhs) { +[[nodiscard]]bool operator!=(const value_type &lhs, const value_type &rhs) { return lhs.value_ != rhs.value_; } template -auto operator+(const value_type &lhs, const value_type &rhs) -> value_type> { +[[nodiscard]]auto operator+(const value_type &lhs, const value_type &rhs) -> value_type> { using U = value_type>; @@ -680,7 +680,7 @@ auto operator+(const value_type &lhs, const value_type &rhs) -> value_ty } template -auto operator-(const value_type &lhs, const value_type &rhs) -> value_type> { +[[nodiscard]]auto operator-(const value_type &lhs, const value_type &rhs) -> value_type> { using U = value_type>; @@ -690,7 +690,7 @@ auto operator-(const value_type &lhs, const value_type &rhs) -> value_ty } template -auto operator*(const value_type &lhs, const value_type &rhs) -> value_type> { +[[nodiscard]]auto operator*(const value_type &lhs, const value_type &rhs) -> value_type> { using U = value_type>; @@ -700,7 +700,7 @@ auto operator*(const value_type &lhs, const value_type &rhs) -> value_ty } template -auto operator/(const value_type &lhs, const value_type &rhs) -> value_type> { +[[nodiscard]]auto operator/(const value_type &lhs, const value_type &rhs) -> value_type> { using U = value_type>; @@ -710,7 +710,7 @@ auto operator/(const value_type &lhs, const value_type &rhs) -> value_ty } template -auto operator%(const value_type &lhs, const value_type &rhs) -> value_type> { +[[nodiscard]]auto operator%(const value_type &lhs, const value_type &rhs) -> value_type> { using U = value_type>; @@ -720,7 +720,7 @@ auto operator%(const value_type &lhs, const value_type &rhs) -> value_ty } template -auto operator&(const value_type &lhs, const value_type &rhs) -> value_type> { +[[nodiscard]]auto operator&(const value_type &lhs, const value_type &rhs) -> value_type> { using U = value_type>; @@ -730,7 +730,7 @@ auto operator&(const value_type &lhs, const value_type &rhs) -> value_ty } template -auto operator|(const value_type &lhs, const value_type &rhs) -> value_type> { +[[nodiscard]]auto operator|(const value_type &lhs, const value_type &rhs) -> value_type> { using U = value_type>; @@ -740,7 +740,7 @@ auto operator|(const value_type &lhs, const value_type &rhs) -> value_ty } template -auto operator^(const value_type &lhs, const value_type &rhs) -> value_type> { +[[nodiscard]]auto operator^(const value_type &lhs, const value_type &rhs) -> value_type> { using U = value_type>; @@ -788,27 +788,27 @@ struct value_type80 { } public: - bool negative() const { + [[nodiscard]] bool negative() const { return value_[9] & 0x80; } - value_type exponent() const { + [[nodiscard]] value_type exponent() const { value_type e(value_, 8); e &= 0x7fff; return e; } - value_type mantissa() const { + [[nodiscard]] value_type mantissa() const { value_type m(value_, 0); return m; } - bool normalized() const { + [[nodiscard]] bool normalized() const { return value_[7] & 0x80; } public: - long double toFloatValue() const { + [[nodiscard]] long double toFloatValue() const { #ifdef _MSC_VER double d; long_double_to_double(&value_, &d); @@ -821,7 +821,7 @@ struct value_type80 { } public: - QString toHexString() const { + [[nodiscard]] QString toHexString() const { char buf[32]; snprintf(buf, sizeof(buf), "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", value_[9], @@ -839,8 +839,8 @@ struct value_type80 { } public: - bool operator==(const value_type80 &rhs) const { return std::memcmp(value_, rhs.value_, 10) == 0; } - bool operator!=(const value_type80 &rhs) const { return std::memcmp(value_, rhs.value_, 10) != 0; } + [[nodiscard]] bool operator==(const value_type80 &rhs) const { return std::memcmp(value_, rhs.value_, 10) == 0; } + [[nodiscard]] bool operator!=(const value_type80 &rhs) const { return std::memcmp(value_, rhs.value_, 10) != 0; } private: T value_ = {}; diff --git a/plugins/BinaryInfo/ELFXX.cpp b/plugins/BinaryInfo/ELFXX.cpp index 7b9e61429..fba828421 100644 --- a/plugins/BinaryInfo/ELFXX.cpp +++ b/plugins/BinaryInfo/ELFXX.cpp @@ -35,33 +35,33 @@ along with this program. If not, see . namespace BinaryInfoPlugin { class ELFBinaryException : public std::exception { - const char *what() const noexcept override = 0; + [[nodiscard]] const char *what() const noexcept override = 0; }; class InvalidArguments : public ELFBinaryException { public: - const char *what() const noexcept override { + [[nodiscard]] const char *what() const noexcept override { return "Invalid Arguments"; } }; class ReadFailure : public ELFBinaryException { public: - const char *what() const noexcept override { + [[nodiscard]] const char *what() const noexcept override { return "Read Failure"; } }; class InvalidELF : public ELFBinaryException { public: - const char *what() const noexcept override { + [[nodiscard]] const char *what() const noexcept override { return "Invalid ELF"; } }; class InvalidArchitecture : public ELFBinaryException { public: - const char *what() const noexcept override { + [[nodiscard]] const char *what() const noexcept override { return "Invalid Architecture"; } }; diff --git a/plugins/BinaryInfo/ELFXX.h b/plugins/BinaryInfo/ELFXX.h index be3280a30..3fcfee830 100644 --- a/plugins/BinaryInfo/ELFXX.h +++ b/plugins/BinaryInfo/ELFXX.h @@ -31,11 +31,11 @@ class ELFXX : public IBinary { ~ELFXX() override = default; public: - bool native() const override; - edb::address_t entryPoint() override; - size_t headerSize() const override; - const void *header() const override; - std::vector
headers() const override; + [[nodiscard]] bool native() const override; + [[nodiscard]] edb::address_t entryPoint() override; + [[nodiscard]] size_t headerSize() const override; + [[nodiscard]] const void *header() const override; + [[nodiscard]] std::vector
headers() const override; private: void validateHeader(); diff --git a/plugins/BinaryInfo/PE32.h b/plugins/BinaryInfo/PE32.h index 41c114e7c..b477e844b 100644 --- a/plugins/BinaryInfo/PE32.h +++ b/plugins/BinaryInfo/PE32.h @@ -35,7 +35,7 @@ class PEBinaryException : public std::exception { public: explicit PEBinaryException(Reason reason); - const char *what() const noexcept override; + [[nodiscard]] const char *what() const noexcept override; private: Reason reason_; @@ -47,11 +47,11 @@ class PE32 : public IBinary { ~PE32() override = default; public: - bool native() const override; - edb::address_t entryPoint() override; - size_t headerSize() const override; - const void *header() const override; - std::vector
headers() const override; + [[nodiscard]] bool native() const override; + [[nodiscard]] edb::address_t entryPoint() override; + [[nodiscard]] size_t headerSize() const override; + [[nodiscard]] const void *header() const override; + [[nodiscard]] std::vector
headers() const override; private: std::shared_ptr region_; diff --git a/plugins/BinaryInfo/symbols.cpp b/plugins/BinaryInfo/symbols.cpp index 386a624e8..a64fc75e9 100644 --- a/plugins/BinaryInfo/symbols.cpp +++ b/plugins/BinaryInfo/symbols.cpp @@ -59,15 +59,15 @@ struct elf32_model : elf_model<32> { QString name; char type; - bool operator<(const symbol &rhs) const { + [[nodiscard]] bool operator<(const symbol &rhs) const { return std::tie(address, name) < std::tie(rhs.address, rhs.name); } - bool operator==(const symbol &rhs) const { + [[nodiscard]] bool operator==(const symbol &rhs) const { return std::tie(address, name) == std::tie(rhs.address, rhs.name); } - QString to_string() const { + [[nodiscard]] QString to_string() const { return QString("%1 %2 %3 %4").arg(edb::value32(address).toHexString(), edb::value32(size).toHexString()).arg(type).arg(name); } }; @@ -88,21 +88,21 @@ struct elf64_model : elf_model<64> { QString name; char type; - bool operator<(const symbol &rhs) const { + [[nodiscard]] bool operator<(const symbol &rhs) const { return std::tie(address, name) < std::tie(rhs.address, rhs.name); } - bool operator==(const symbol &rhs) const { + [[nodiscard]] bool operator==(const symbol &rhs) const { return std::tie(address, name) == std::tie(rhs.address, rhs.name); } - QString to_string() const { + [[nodiscard]] QString to_string() const { return QString("%1 %2 %3 %4").arg(edb::value64(address).toHexString(), edb::value32(size).toHexString()).arg(type).arg(name); } }; }; -bool is_elf32(const void *ptr) { +[[nodiscard]] bool is_elf32(const void *ptr) { auto elf32_hdr = reinterpret_cast(ptr); if (std::memcmp(elf32_hdr->e_ident, ELFMAG, SELFMAG) == 0) { return elf32_hdr->e_ident[EI_CLASS] == ELFCLASS32; @@ -110,7 +110,7 @@ bool is_elf32(const void *ptr) { return false; } -bool is_elf64(const void *ptr) { +[[nodiscard]] bool is_elf64(const void *ptr) { auto elf64_hdr = reinterpret_cast(ptr); if (std::memcmp(elf64_hdr->e_ident, ELFMAG, SELFMAG) == 0) { return elf64_hdr->e_ident[EI_CLASS] == ELFCLASS64; diff --git a/plugins/DumpState/DumpState.cpp b/plugins/DumpState/DumpState.cpp index 544477c50..fef8c60de 100644 --- a/plugins/DumpState/DumpState.cpp +++ b/plugins/DumpState/DumpState.cpp @@ -69,9 +69,9 @@ std::string format_register(const T &value) { if (colorize) { return Blue + hex_string(value) + Reset; - } else { - return hex_string(value); } + + return hex_string(value); } /** @@ -87,9 +87,9 @@ std::string format_segment(const T &value) { if (colorize) { return Green + hex_string(value) + Reset; - } else { - return hex_string(value); } + + return hex_string(value); } /** @@ -105,9 +105,9 @@ std::string format_address(const T &value) { if (colorize) { return Purple + hex_string(value) + Reset; - } else { - return hex_string(value); } + + return hex_string(value); } } @@ -269,18 +269,22 @@ void DumpState::dumpLines(edb::address_t address, int lines) { std::cout << hex_string(address) << " : "; - for (int j = 0x00; j < 0x04; ++j) + for (int j = 0x00; j < 0x04; ++j) { std::cout << hex_string(buf[j]) << " "; + } std::cout << " "; - for (int j = 0x04; j < 0x08; ++j) + for (int j = 0x04; j < 0x08; ++j) { std::cout << hex_string(buf[j]) << " "; + } std::cout << "- "; - for (int j = 0x08; j < 0x0c; ++j) + for (int j = 0x08; j < 0x0c; ++j) { std::cout << hex_string(buf[j]) << " "; + } std::cout << " "; - for (int j = 0x0c; j < 0x10; ++j) + for (int j = 0x0c; j < 0x10; ++j) { std::cout << hex_string(buf[j]) << " "; + } for (int j = 0; j < 16; ++j) { // TODO(eteran): why won't this compile with MSVC? diff --git a/src/FixedFontSelector.cpp b/src/FixedFontSelector.cpp index bbc01c10c..03c1ef191 100644 --- a/src/FixedFontSelector.cpp +++ b/src/FixedFontSelector.cpp @@ -35,7 +35,7 @@ FixedFontSelector::FixedFontSelector(QWidget *parent, Qt::WindowFlags f) //------------------------------------------------------------------------------ // Name: //------------------------------------------------------------------------------ -QFont FixedFontSelector::currentFont() { +QFont FixedFontSelector::currentFont() const { return ui.fontCombo->currentFont(); } diff --git a/src/FixedFontSelector.h b/src/FixedFontSelector.h index 866aaf760..abeb4eb8d 100644 --- a/src/FixedFontSelector.h +++ b/src/FixedFontSelector.h @@ -31,7 +31,7 @@ class FixedFontSelector : public QWidget { ~FixedFontSelector() override = default; public: - QFont currentFont(); + [[nodiscard]] QFont currentFont() const; public Q_SLOTS: void setCurrentFont(const QFont &font); diff --git a/src/capstone-edb/include/Instruction.h b/src/capstone-edb/include/Instruction.h index 18f608876..406816f7e 100644 --- a/src/capstone-edb/include/Instruction.h +++ b/src/capstone-edb/include/Instruction.h @@ -66,7 +66,7 @@ class EDB_EXPORT Instruction { return insn_; } - explicit operator bool() const { + [[nodiscard]] explicit operator bool() const { return valid(); } diff --git a/src/capstone-edb/include/Operand.h b/src/capstone-edb/include/Operand.h index 6d2faadf4..c12d251c0 100644 --- a/src/capstone-edb/include/Operand.h +++ b/src/capstone-edb/include/Operand.h @@ -36,7 +36,7 @@ class Operand { public: [[nodiscard]] bool valid() const { return operand_; } - explicit operator bool() const { return valid(); } + [[nodiscard]] explicit operator bool() const { return valid(); } const op_type *operator->() const { return operand_; } [[nodiscard]] const op_type *native() const { return operand_; } [[nodiscard]] size_t index() const { return index_; }