Skip to content

Commit

Permalink
Fix thread and process widget API usage to match dpT and dp behavior. (
Browse files Browse the repository at this point in the history
…#3411)


Add PC and TLS columns to thread widget.
  • Loading branch information
karliss authored Feb 3, 2025
1 parent cb6035a commit d8bd8d4
Show file tree
Hide file tree
Showing 7 changed files with 234 additions and 87 deletions.
44 changes: 37 additions & 7 deletions src/core/Cutter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <cassert>
#include <memory>

#include "CutterDescriptions.h"
#include "common/TempConfig.h"
#include "common/BasicInstructionHighlighter.h"
#include "common/Configuration.h"
Expand Down Expand Up @@ -2801,33 +2802,62 @@ bool CutterCore::isBreakpoint(const QList<RVA> &breakpoints, RVA addr)
return breakpoints.contains(addr);
}

QList<ProcessDescription> CutterCore::getProcessThreads(int pid = -1)
QList<ThreadDescription> CutterCore::getProcessThreads(int pid)
{
CORE_LOCK();
RzList *list = rz_debug_pids(core->dbg, pid != -1 ? pid : core->dbg->pid);
auto dbg = core_->dbg;
if (!dbg || !dbg->cur || !dbg->cur->threads) {
return {};
}
RzList *list = core_->dbg->cur->threads(dbg, pid != -1 ? pid : dbg->pid);
RzListIter *iter;
RzDebugPid *p;
QList<ProcessDescription> ret;
QList<ThreadDescription> ret;

CutterRzListForeach (list, iter, RzDebugPid, p) {
ProcessDescription proc;
ThreadDescription proc;

proc.current = core->dbg->pid == p->pid;
proc.current = dbg->tid == p->pid;
proc.ppid = p->ppid;
proc.pid = p->pid;
proc.uid = p->uid;
proc.status = static_cast<RzDebugPidState>(p->status);
proc.path = p->path;
proc.pc = p->pc;
proc.tls = p->tls;

ret << proc;
}
rz_list_free(list);
return ret;
}

QList<ProcessDescription> CutterCore::getAllProcesses()
QList<ProcessDescription> CutterCore::getProcesses(int pid)
{
return getProcessThreads(0);
CORE_LOCK();
auto dbg = core_->dbg;
if (!dbg || !dbg->cur || !dbg->cur->threads) {
return {};
}
RzList *list = core_->dbg->cur->pids(dbg, pid >= 0 ? pid : dbg->pid);
RzListIter *iter;
RzDebugPid *p;
QList<ProcessDescription> ret;

CutterRzListForeach (list, iter, RzDebugPid, p) {
ProcessDescription proc;

proc.current = core->dbg->pid == p->pid;
proc.ppid = p->ppid;
proc.pid = p->pid;
proc.uid = p->uid;
proc.status = static_cast<RzDebugPidState>(p->status);
proc.path = p->path;

ret << proc;
}
rz_list_free(list);
return ret;
}

QList<MemoryMapDescription> CutterCore::getMemoryMap()
Expand Down
10 changes: 8 additions & 2 deletions src/core/Cutter.h
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ class CUTTER_EXPORT CutterCore : public QObject
* @param pid The pid of the process, -1 for the currently debugged process
* @return List of ProcessDescription
*/
QList<ProcessDescription> getProcessThreads(int pid);
QList<ThreadDescription> getProcessThreads(int pid = -1);
/**
* @brief Get a list of heap chunks
* Uses RZ_API rz_heap_chunks_list to get vector of chunks
Expand Down Expand Up @@ -652,7 +652,13 @@ class CUTTER_EXPORT CutterCore : public QObject
QList<MemoryMapDescription> getMemoryMap();
QList<SearchDescription> getAllSearch(QString searchFor, QString space, QString in);
QList<BreakpointDescription> getBreakpoints();
QList<ProcessDescription> getAllProcesses();
/**
* @brief Get list of processes attachable by debugger
*
* @param pid 0 - all processes, -1 - currently debugged process
* @return QList<ProcessDescription>
*/
QList<ProcessDescription> getProcesses(int pid = 0);
/**
* @brief Get the right RzReg object based on the cutter state (debugging vs emulating)
*/
Expand Down
12 changes: 12 additions & 0 deletions src/core/CutterDescriptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,18 @@ struct ProcessDescription
QString path;
};

struct ThreadDescription
{
bool current;
int pid;
int uid;
int ppid;
RzDebugPidState status;
QString path;
ut64 pc;
ut64 tls;
};

struct RefDescription
{
QString ref;
Expand Down
2 changes: 1 addition & 1 deletion src/dialogs/AttachProcDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void ProcessModel::updateData()
{
beginResetModel();

processes = Core()->getAllProcesses();
processes = Core()->getProcesses();

endResetModel();
}
Expand Down
4 changes: 2 additions & 2 deletions src/widgets/ProcessesWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void ProcessesWidget::setProcessesGrid()
int i = 0;
QFont font;

for (const auto &processesItem : Core()->getProcessThreads(DEBUGGED_PID)) {
for (const auto &processesItem : Core()->getProcesses(DEBUGGED_PID)) {
st64 pid = processesItem.pid;
st64 uid = processesItem.uid;
QString status = translateStatus(processesItem.status);
Expand Down Expand Up @@ -155,7 +155,7 @@ void ProcessesWidget::onActivated(const QModelIndex &index)
int pid = modelFilter->data(index.sibling(index.row(), ProcessesWidget::COLUMN_PID)).toInt();
// Verify that the selected pid is still in the processes list since dp= will
// attach to any given id. If it isn't found simply update the UI.
for (const auto &value : Core()->getAllProcesses()) {
for (const auto &value : Core()->getProcesses(DEBUGGED_PID)) {
if (pid == value.pid) {
QMessageBox msgBox(this);
switch (value.status) {
Expand Down
Loading

0 comments on commit d8bd8d4

Please sign in to comment.