Skip to content

Commit

Permalink
fixed an accidental infinite recursion in the breakpoint::setType
Browse files Browse the repository at this point in the history
moar [[nodiscard]]
some other stylistic cleanup
  • Loading branch information
eteran committed Mar 19, 2024
1 parent b859fe1 commit e3c8936
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 88 deletions.
15 changes: 7 additions & 8 deletions plugins/DebuggerCore/arch/arm-generic/Breakpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,18 @@ auto Breakpoint::supportedTypes() -> std::vector<BreakpointType> {
return types;
}

void Breakpoint::setType(TypeId type) {
void Breakpoint::setType(IBreakpoint::TypeId type) {
disable();
type_ = type;
if (!enable()) {

if (Type{type} >= TypeId::TYPE_COUNT) {
throw BreakpointCreationError();
}
}

void Breakpoint::setType(IBreakpoint::TypeId type) {
disable();
if (Type{type} >= TypeId::TYPE_COUNT)
type_ = type;

if (!enable()) {
throw BreakpointCreationError();
setType(type);
}
}

//------------------------------------------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion plugins/DebuggerCore/arch/arm-generic/Breakpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ class Breakpoint final : public IBreakpoint {
void setOneTime(bool value) override;
void setInternal(bool value) override;
void setType(IBreakpoint::TypeId type) override;
void setType(TypeId type);

private:
std::vector<uint8_t> originalBytes_;
Expand Down
18 changes: 5 additions & 13 deletions plugins/DebuggerCore/arch/x86-generic/Breakpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,6 @@ auto Breakpoint::supportedTypes() -> std::vector<BreakpointType> {
return types;
}

/**
* @brief Breakpoint::setType
* @param type
*/
void Breakpoint::setType(TypeId type) {
disable();
type_ = type;
if (!enable()) {
throw BreakpointCreationError();
}
}

/**
* @brief Breakpoint::setType
* @param type
Expand All @@ -96,7 +84,11 @@ void Breakpoint::setType(IBreakpoint::TypeId type) {
throw BreakpointCreationError();
}

setType(type);
type_ = type;

if (!enable()) {
throw BreakpointCreationError();
}
}

/**
Expand Down
3 changes: 1 addition & 2 deletions plugins/DebuggerCore/arch/x86-generic/Breakpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace DebuggerCorePlugin {
class Breakpoint final : public IBreakpoint {
Q_DECLARE_TR_FUNCTIONS(Breakpoint)
public:
enum class TypeId {
enum class TypeId : int {
Automatic = static_cast<int>(IBreakpoint::TypeId::Automatic),
INT3,
INT1,
Expand Down Expand Up @@ -73,7 +73,6 @@ class Breakpoint final : public IBreakpoint {
void setOneTime(bool value) override;
void setInternal(bool value) override;
void setType(IBreakpoint::TypeId type) override;
void setType(TypeId type);

private:
std::vector<uint8_t> originalBytes_;
Expand Down
2 changes: 1 addition & 1 deletion plugins/DebuggerCore/unix/linux/PlatformThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class PlatformThread final : public IThread {
#endif

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

private:
Expand Down
30 changes: 20 additions & 10 deletions plugins/DebuggerCore/unix/linux/arch/x86-generic/PlatformState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -901,27 +901,32 @@ Register PlatformState::value(const QString &reg) const {

if (is64Bit()) {
return make_Register(regName, value, Register::TYPE_SEG);
} else {
return make_Register<32>(regName, value, Register::TYPE_SEG);
}

return make_Register<32>(regName, value, Register::TYPE_SEG);
}
}

if (is64Bit() && regName == X86::flags64Name) {
return make_Register(X86::flags64Name, x86.flags, Register::TYPE_COND);
}

if (regName == X86::flags32Name) {
return make_Register<32>(X86::flags32Name, x86.flags, Register::TYPE_COND);
}

if (regName == X86::flags16Name) {
return make_Register<16>(X86::flags16Name, x86.flags, Register::TYPE_COND);
}

if (is64Bit() && regName == X86::IP64Name) {
return make_Register(X86::IP64Name, x86.IP, Register::TYPE_IP);
}

if (regName == X86::IP32Name) {
return make_Register<32>(X86::IP32Name, x86.IP, Register::TYPE_IP);
}

if (regName == X86::IP16Name) {
return make_Register<16>(X86::IP16Name, x86.IP, Register::TYPE_IP);
}
Expand All @@ -938,9 +943,9 @@ Register PlatformState::value(const QString &reg) const {

if (is64Bit() && x86.gpr64Filled) {
return make_Register(regName, x86.dbgRegs[i], Register::TYPE_COND);
} else {
return make_Register<32>(regName, x86.dbgRegs[i], Register::TYPE_COND);
}

return make_Register<32>(regName, x86.dbgRegs[i], Register::TYPE_COND);
}
}

Expand Down Expand Up @@ -973,9 +978,9 @@ Register PlatformState::value(const QString &reg) const {
const edb::address_t addr = regName == "fip" ? x87.instPtrOffset : x87.dataPtrOffset;
if (is64Bit()) {
return make_Register<64>(regName, addr, Register::TYPE_FPU);
} else {
return make_Register<32>(regName, addr, Register::TYPE_FPU);
}

return make_Register<32>(regName, addr, Register::TYPE_FPU);
}

if (regName == "fis" || regName == "fds") {
Expand Down Expand Up @@ -1055,7 +1060,9 @@ Register PlatformState::instructionPointerRegister() const {

if (x86.gpr64Filled && is64Bit()) {
return make_Register(X86::IP64Name, x86.IP, Register::TYPE_GPR);
} else if (x86.gpr32Filled) {
}

if (x86.gpr32Filled) {
return make_Register<32>(X86::IP32Name, x86.IP, Register::TYPE_GPR);
}

Expand Down Expand Up @@ -1103,7 +1110,9 @@ edb::reg_t PlatformState::debugRegister(size_t n) const {
Register PlatformState::flagsRegister() const {
if (x86.gpr64Filled && is64Bit()) {
return make_Register(X86::flags64Name, x86.flags, Register::TYPE_GPR);
} else if (x86.gpr32Filled) {
}

if (x86.gpr32Filled) {
return make_Register<32>(X86::flags32Name, x86.flags, Register::TYPE_GPR);
}

Expand Down Expand Up @@ -1135,7 +1144,6 @@ edb::value80 PlatformState::fpuRegister(size_t n) const {
assert(fpuIndexValid(n));

if (!x87.filled) {

edb::value80 v;
constexpr std::uint64_t Mant = 0x0badbad1bad1bad1;
constexpr std::uint16_t Exp = 0x0bad;
Expand Down Expand Up @@ -1259,7 +1267,9 @@ Register PlatformState::gpRegister(size_t n) const {
if (gprIndexValid(n)) {
if (x86.gpr64Filled && is64Bit()) {
return make_Register(X86::GPReg64Names[n], x86.GPRegs[n], Register::TYPE_GPR);
} else if (x86.gpr32Filled && n < IA32_GPR_COUNT) {
}

if (x86.gpr32Filled && n < IA32_GPR_COUNT) {
return make_Register<32>(X86::GPReg32Names[n], x86.GPRegs[n], Register::TYPE_GPR);
}
}
Expand Down
Loading

0 comments on commit e3c8936

Please sign in to comment.