Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/libELF/include/libELF/elf_syminfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ enum {

template <class T>
constexpr T ELF32_ST_VISIBILITY(T o) {
return ((o)&0x03);
return ((o) & 0x03);
}

/* For ELF64 the definitions are the same. */
Expand Down
12 changes: 7 additions & 5 deletions plugins/Analyzer/Analyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,11 +368,13 @@

Q_ASSERT(data);

const QString s = edb::v1::debugger_core->process()->executable();
if (!s.isEmpty()) {
if (const edb::address_t main = edb::v1::locate_main_function()) {
if (data->region->contains(main)) {
data->knownFunctions.insert(main);
if (IProcess *process = edb::v1::debugger_core->process()) {

Check warning on line 371 in plugins/Analyzer/Analyzer.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Make the type of this variable a pointer-to-const. The current type of "process" is "class IProcess *".

See more on https://sonarcloud.io/project/issues?id=eteran_edb-debugger&issues=AZ0Glqnd5uVuQHfQsDRH&open=AZ0Glqnd5uVuQHfQsDRH&pullRequest=889
const QString s = process->executable();
if (!s.isEmpty()) {
if (const edb::address_t main = edb::v1::locate_main_function()) {
if (data->region->contains(main)) {

Check failure on line 375 in plugins/Analyzer/Analyzer.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this code to not nest more than 3 if|for|do|while|switch statements.

See more on https://sonarcloud.io/project/issues?id=eteran_edb-debugger&issues=AZ0Glqnd5uVuQHfQsDRG&open=AZ0Glqnd5uVuQHfQsDRG&pullRequest=889
data->knownFunctions.insert(main);
}
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions plugins/BinaryInfo/ELFXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
};

template <class ElfHeader>
ELFXX<ElfHeader>::ELFXX(const std::shared_ptr<IRegion> &region)

Check failure on line 58 in plugins/BinaryInfo/ELFXX.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this function to reduce its Cognitive Complexity from 27 to the 25 allowed.

See more on https://sonarcloud.io/project/issues?id=eteran_edb-debugger&issues=AZ0Glqm75uVuQHfQsDRC&open=AZ0Glqm75uVuQHfQsDRC&pullRequest=889
: region_(region) {

using phdr_type = typename ElfHeader::elf_phdr;
Expand Down Expand Up @@ -109,10 +109,12 @@
}
} else if (header_.e_type == ET_DYN) {

const QString process_executable = edb::v1::debugger_core->process()->name();
for (const std::shared_ptr<IRegion> &r : edb::v1::memory_regions().regions()) {
if (r->accessible() && r->name() == region->name()) {
lowest = std::min(lowest, r->start());
if (IProcess *process = edb::v1::debugger_core->process()) {

Check warning on line 112 in plugins/BinaryInfo/ELFXX.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Make the type of this variable a pointer-to-const. The current type of "process" is "class IProcess *".

See more on https://sonarcloud.io/project/issues?id=eteran_edb-debugger&issues=AZ0Glqm75uVuQHfQsDRF&open=AZ0Glqm75uVuQHfQsDRF&pullRequest=889

Check warning on line 112 in plugins/BinaryInfo/ELFXX.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Declaration shadows a local variable "process" in the outer scope.

See more on https://sonarcloud.io/project/issues?id=eteran_edb-debugger&issues=AZ0Glqm75uVuQHfQsDRE&open=AZ0Glqm75uVuQHfQsDRE&pullRequest=889
const QString process_executable = process->name();
for (const std::shared_ptr<IRegion> &r : edb::v1::memory_regions().regions()) {
if (r->accessible() && r->name() == region->name()) {

Check failure on line 115 in plugins/BinaryInfo/ELFXX.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this code to not nest more than 3 if|for|do|while|switch statements.

See more on https://sonarcloud.io/project/issues?id=eteran_edb-debugger&issues=AZ0Glqm75uVuQHfQsDRD&open=AZ0Glqm75uVuQHfQsDRD&pullRequest=889
lowest = std::min(lowest, r->start());
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/CheckVersion/CheckVersion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ void CheckVersion::setProxy(const QUrl &url) {
if (!proxy_str.isEmpty()) {
const QUrl proxy_url = QUrl::fromUserInput(proxy_str);
const int port = proxy_url.port(80);
const auto qport = static_cast<quint16>(qBound(0, port, 65535));
const auto qport = static_cast<quint16>(qBound(0, port, 65535));

proxy = QNetworkProxy(QNetworkProxy::HttpProxy, proxy_url.host(), qport, proxy_url.userName(), proxy_url.password());
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/DebuggerCore/unix/openbsd/PlatformState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ void PlatformState::set_instruction_pointer(edb::address_t value) {
#if defined(EDB_X86)
regs_.r_eip = value;
#elif defined(EDB_X86_64)
regs_.r_rip = value;
regs_.r_rip = value;
#endif
}

Expand Down
6 changes: 3 additions & 3 deletions plugins/DebuggerCore/unix/osx/DebuggerCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,9 @@ void DebuggerCore::set_state(const State &state) {
// const thread_state_flavor_t fpu_flavor = x86_FLOAT_STATE32;
// const thread_state_flavor_t exception_flavor = x86_EXCEPTION_STATE32;
#elif defined(EDB_X86_64)
mach_msg_type_number_t state_count = x86_THREAD_STATE64_COUNT;
const thread_state_flavor_t flavor = x86_THREAD_STATE64;
const thread_state_flavor_t debug_flavor = x86_DEBUG_STATE64;
mach_msg_type_number_t state_count = x86_THREAD_STATE64_COUNT;
const thread_state_flavor_t flavor = x86_THREAD_STATE64;
const thread_state_flavor_t debug_flavor = x86_DEBUG_STATE64;
// const thread_state_flavor_t fpu_flavor = x86_FLOAT_STATE64;
// const thread_state_flavor_t exception_flavor = x86_EXCEPTION_STATE64;
#endif
Expand Down
2 changes: 1 addition & 1 deletion plugins/DebuggerCore/unix/osx/PlatformState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ void PlatformState::set_instruction_pointer(edb::address_t value) {
#if defined(EDB_X86)
thread_state_.REG(eip) = value;
#elif defined(EDB_X86_64)
thread_state_.REG(rip) = value;
thread_state_.REG(rip) = value;
#endif
}

Expand Down
75 changes: 39 additions & 36 deletions plugins/DebuggerCore/win32/PlatformRegion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,44 +113,47 @@ size_t PlatformRegion::size() const {
* @param execute
*/
void PlatformRegion::setPermissions(bool read, bool write, bool execute) {
if (HANDLE ph = OpenProcess(PROCESS_VM_OPERATION, FALSE, edb::v1::debugger_core->process()->pid())) {
DWORD prot = PAGE_NOACCESS;

switch ((static_cast<int>(read) << 2) | (static_cast<int>(write) << 1) | (static_cast<int>(execute) << 0)) {
case 0x0:
prot = PAGE_NOACCESS;
break;
case 0x1:
prot = PAGE_EXECUTE;
break;
case 0x2:
prot = PAGE_WRITECOPY;
break;
case 0x3:
prot = PAGE_EXECUTE_WRITECOPY;
break;
case 0x4:
prot = PAGE_READONLY;
break;
case 0x5:
prot = PAGE_EXECUTE_READ;
break;
case 0x6:
prot = PAGE_READWRITE;
break;
case 0x7:
prot = PAGE_EXECUTE_READWRITE;
break;
}

prot |= permissions_ & ~KnownPermissions; // keep modifiers

DWORD prev_prot;
if (VirtualProtectEx(ph, reinterpret_cast<LPVOID>(start().toUint()), size(), prot, &prev_prot)) {
permissions_ = prot;
if (IProcess *process = edb::v1::debugger_core->process()) {
if (HANDLE ph = OpenProcess(PROCESS_VM_OPERATION, FALSE, process->pid())) {
DWORD prot = PAGE_NOACCESS;

switch ((static_cast<int>(read) << 2) | (static_cast<int>(write) << 1) | (static_cast<int>(execute) << 0)) {
case 0x0:
prot = PAGE_NOACCESS;
break;
case 0x1:
prot = PAGE_EXECUTE;
break;
case 0x2:
prot = PAGE_WRITECOPY;
break;
case 0x3:
prot = PAGE_EXECUTE_WRITECOPY;
break;
case 0x4:
prot = PAGE_READONLY;
break;
case 0x5:
prot = PAGE_EXECUTE_READ;
break;
case 0x6:
prot = PAGE_READWRITE;
break;
case 0x7:
prot = PAGE_EXECUTE_READWRITE;
break;
}

prot |= permissions_ & ~KnownPermissions; // keep modifiers

DWORD prev_prot;
if (VirtualProtectEx(ph, reinterpret_cast<LPVOID>(start().toUint()), size(), prot, &prev_prot)) {
permissions_ = prot;
}

CloseHandle(ph);
}

CloseHandle(ph);
}
}

Expand Down
4 changes: 2 additions & 2 deletions plugins/ODbgRegisterView/DialogEditGPR.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ private Q_SLOTS:
void setupFocus();

private:
std::array<QLabel *, ENTRY_COLS + ENTRY_ROWS> labels_ = {{nullptr}};
std::array<GprEdit *, FULL_LENGTH_ROWS *ENTRY_COLS + CHAR_COLS> entries_ = {{nullptr}};
std::array<QLabel *, ENTRY_COLS + ENTRY_ROWS> labels_ = {{nullptr}};
std::array<GprEdit *, FULL_LENGTH_ROWS * ENTRY_COLS + CHAR_COLS> entries_ = {{nullptr}};
std::uint64_t value_;
std::size_t bitSize_ = 0;
Register reg_;
Expand Down
2 changes: 1 addition & 1 deletion plugins/ODbgRegisterView/Plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void Plugin::setupDocks() {

void Plugin::saveSettings() const {
QSettings settings;
const auto size = static_cast<int>(registerViews_.size());
const auto size = static_cast<int>(registerViews_.size());
const auto arrayKey = pluginName + "/" + views;
settings.remove(arrayKey);
settings.beginWriteArray(arrayKey, size);
Expand Down
3 changes: 1 addition & 2 deletions plugins/ODbgRegisterView/arch/arm-generic/armGroups.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ RegisterGroup *createCPSR(RegisterViewModelBase::Model *model, QWidget *parent)
const auto valueWidth = 8;
const auto valueIndex = nameIndex.sibling(nameIndex.row(), ModelValueColumn);
column += nameWidth + 1;
group->insert(0, column, new ValueField(
valueWidth, valueIndex, [](QString const &v) { return v.right(8); }, group));
group->insert(0, column, new ValueField(valueWidth, valueIndex, [](QString const &v) { return v.right(8); }, group));
const auto commentIndex = nameIndex.sibling(nameIndex.row(), ModelCommentColumn);
column += valueWidth + 1;
group->insert(0, column, new FieldWidget(0, commentIndex, group));
Expand Down
6 changes: 1 addition & 5 deletions plugins/ODbgRegisterView/arch/x86-generic/x86Groups.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,7 @@ RegisterGroup *create_eflags(RegisterViewModelBase::Model *model, QWidget *paren
constexpr int ValueWidth = 8;
const auto valueIndex = nameIndex.sibling(nameIndex.row(), ModelValueColumn);
column += NameWidth + 1;
group->insert(0, column, new ValueField(
ValueWidth, valueIndex, [](const QString &v) {
return v.right(8);
},
group));
group->insert(0, column, new ValueField(ValueWidth, valueIndex, [](const QString &v) { return v.right(8); }, group));

const auto commentIndex = nameIndex.sibling(nameIndex.row(), ModelCommentColumn);
column += ValueWidth + 1;
Expand Down
24 changes: 24 additions & 0 deletions scripts/clang-format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash
set -euo pipefail

cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." || exit 1

EXCLUDED_DIRS="lib/gdtoa-desktop src/qhexview/"

EXCLUDE_PATH_ARGS=()
for dir in $EXCLUDED_DIRS; do
dir="${dir%/}"
EXCLUDE_PATH_ARGS+=( -path "$dir" -o -path "$dir/*" -o )
done

# Remove trailing "-o" so the prune expression is valid.
if [ ${#EXCLUDE_PATH_ARGS[@]} -gt 0 ]; then

Check failure on line 15 in scripts/clang-format.sh

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use '[[' instead of '[' for conditional tests. The '[[' construct is safer and more feature-rich.

See more on https://sonarcloud.io/project/issues?id=eteran_edb-debugger&issues=AZ0Glqpr5uVuQHfQsDRI&open=AZ0Glqpr5uVuQHfQsDRI&pullRequest=889
unset 'EXCLUDE_PATH_ARGS[${#EXCLUDE_PATH_ARGS[@]}-1]'
FILES=$(find include src plugins lib \
\( "${EXCLUDE_PATH_ARGS[@]}" \) -prune -o \
-type f \( -name "*.cpp" -o -name "*.h" \) -print)
else
FILES=$(find include src plugins lib -type f \( -name "*.cpp" -o -name "*.h" \))
fi

echo $FILES | xargs clang-format -i
64 changes: 40 additions & 24 deletions src/Debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,13 @@

if (IProcess *process = edb::v1::debugger_core->process()) {

std::shared_ptr<IThread> thread = process->currentThread();
if (!thread) {
return pass_back_to_debugger();
}

State state;
process->currentThread()->getState(&state);
thread->getState(&state);

edb::address_t address = state.instructionPointer();
IDebugEvent::TRAP_REASON trap_reason = event->trapReason();
Expand Down Expand Up @@ -251,7 +256,7 @@

// Adjust RIP since 1st byte was replaced with 0xcc and we are now 1 byte after it.
state.setInstructionPointer(prev_address);
process->currentThread()->setState(state);
thread->setState(state);
address = prev_address;

// If it wasn't internal, it was a user breakpoint. Pass back to Debugger.
Expand Down Expand Up @@ -738,7 +743,11 @@
// Desc: sets the caption part to also show the application name and pid
//------------------------------------------------------------------------------
void Debugger::setDebuggerCaption(const QString &appname) {
setWindowTitle(tr("edb - %1 [%2]").arg(appname).arg(edb::v1::debugger_core->process()->pid()));
if (IProcess *process = edb::v1::debugger_core->process()) {
setWindowTitle(tr("edb - %1 [%2]").arg(appname).arg(process->pid()));
} else {
setWindowTitle(tr("edb"));
}
}

//------------------------------------------------------------------------------
Expand Down Expand Up @@ -1340,9 +1349,11 @@

if (IDebugger *core = edb::v1::debugger_core) {
if (IProcess *process = core->process()) {
State state;
process->currentThread()->getState(&state);
return state[regName];
if (std::shared_ptr<IThread> thread = process->currentThread()) {
State state;
thread->getState(&state);
return state[regName];
}
}
}
return {};
Expand Down Expand Up @@ -2315,8 +2326,11 @@
IProcess *process = edb::v1::debugger_core->process();
Q_ASSERT(process);

std::shared_ptr<IThread> thread = process->currentThread();
Q_ASSERT(thread);

State state;
process->currentThread()->getState(&state);
thread->getState(&state);

// look it up in our breakpoint list, make sure it is one of OUR int3s!
// if it is, we need to backup EIP and pause ourselves
Expand All @@ -2332,7 +2346,7 @@
// back up eip the size of a breakpoint, since we executed a breakpoint
// instead of the real code that belongs there
state.setInstructionPointer(previous_ip);
process->currentThread()->setState(state);
thread->setState(state);

#if defined(Q_OS_LINUX)
// test if we have hit our internal LD hook BP. If so, read in the r_debug
Expand Down Expand Up @@ -2996,8 +3010,7 @@
dynamicInfoBreakpointSet_ = false;
#endif

IProcess *process = edb::v1::debugger_core->process();

IProcess *process = edb::v1::debugger_core->process();
const QString executable = process ? process->executable() : QString();

setDebuggerCaption(executable);
Expand Down Expand Up @@ -3066,7 +3079,9 @@
}

if (entryPoint == 0 || edb::v1::config().initial_breakpoint == Configuration::EntryPoint) {
entryPoint = edb::v1::debugger_core->process()->entryPoint();
if (IProcess *process = edb::v1::debugger_core->process()) {
entryPoint = process->entryPoint();
}
}

if (entryPoint != 0) {
Expand All @@ -3085,13 +3100,13 @@
void Debugger::on_action_Restart_triggered() {

Q_ASSERT(edb::v1::debugger_core);
if (edb::v1::debugger_core->process()) {
if (IProcess *process = edb::v1::debugger_core->process()) {

Check warning on line 3103 in src/Debugger.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Make the type of this variable a pointer-to-const. The current type of "process" is "class IProcess *".

See more on https://sonarcloud.io/project/issues?id=eteran_edb-debugger&issues=AZ0GlqlS5uVuQHfQsDRA&open=AZ0GlqlS5uVuQHfQsDRA&pullRequest=889

workingDirectory_ = edb::v1::debugger_core->process()->currentWorkingDirectory();
QList<QByteArray> args = edb::v1::debugger_core->process()->arguments();
const QString exe = edb::v1::debugger_core->process()->executable();
const QString in = edb::v1::debugger_core->process()->standardInput();
const QString out = edb::v1::debugger_core->process()->standardOutput();
workingDirectory_ = process->currentWorkingDirectory();
QList<QByteArray> args = process->arguments();
const QString exe = process->executable();
const QString in = process->standardInput();
const QString out = process->standardOutput();

if (!args.empty()) {
args.removeFirst();
Expand Down Expand Up @@ -3221,17 +3236,18 @@
}

if (const auto status = edb::v1::debugger_core->attach(pid)) {
if (IProcess *process = edb::v1::debugger_core->process()) {

workingDirectory_ = edb::v1::debugger_core->process()->currentWorkingDirectory();
workingDirectory_ = process->currentWorkingDirectory();
QList<QByteArray> args = process->arguments();

QList<QByteArray> args = edb::v1::debugger_core->process()->arguments();
if (!args.empty()) {
args.removeFirst();
}

if (!args.empty()) {
args.removeFirst();
argumentsDialog_->setArguments(args);
attachComplete();
}

argumentsDialog_->setArguments(args);
attachComplete();
} else {
QMessageBox::critical(this, tr("Attach"), tr("Failed to attach to process: %1").arg(status.error()));
}
Expand Down Expand Up @@ -3473,7 +3489,7 @@
if (stackViewInfo_.region) {
stackViewInfo_.update();

if (IProcess *process = edb::v1::debugger_core->process()) {

Check warning on line 3492 in src/Debugger.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Make the type of this variable a pointer-to-const. The current type of "process" is "class IProcess *".

See more on https://sonarcloud.io/project/issues?id=eteran_edb-debugger&issues=AZ0GlqlS5uVuQHfQsDRB&open=AZ0GlqlS5uVuQHfQsDRB&pullRequest=889
if (std::shared_ptr<IThread> thread = process->currentThread()) {

State state;
Expand Down
Loading
Loading