summaryrefslogtreecommitdiffhomepage
path: root/dev/LibDebugger/src
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2025-03-23 20:58:15 +0100
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2025-03-23 20:58:15 +0100
commitd8cf1ef181caa49bb44ed521ed063cfed3eca775 (patch)
treec6b17ffb5d122ef0d5f00beabde92fe4e0450c32 /dev/LibDebugger/src
parent4b0de97035d2a750c4a2073a1992e2eff68926d0 (diff)
feat(dbg): Avoid breakpoint when kPID is not set (kPID = 0)
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'dev/LibDebugger/src')
-rw-r--r--dev/LibDebugger/src/POSIX.cc24
1 files changed, 14 insertions, 10 deletions
diff --git a/dev/LibDebugger/src/POSIX.cc b/dev/LibDebugger/src/POSIX.cc
index 02db4ea..b8c92ae 100644
--- a/dev/LibDebugger/src/POSIX.cc
+++ b/dev/LibDebugger/src/POSIX.cc
@@ -10,11 +10,17 @@
#ifndef _WIN32
-static bool kKeepRunning = false;
-LibDebugger::POSIX::Debugger kDebugger;
+static bool kKeepRunning = false;
+static LibDebugger::POSIX::LocalDebuggerPOSIX kDebugger;
+static pid_t kPID = 0L;
static void DebuggerCtrlCHandler(std::int32_t _)
{
+ if (!kPID)
+ {
+ return;
+ }
+
auto list = kDebugger.Get();
LibDebugger::POSIX::CAddr addr = (LibDebugger::POSIX::CAddr)list[list.size() - 1];
@@ -39,13 +45,11 @@ LIBCOMPILER_MODULE(DebuggerPOSIX)
return EXIT_FAILURE;
}
- pid_t pid = 0L;
-
if (argc >= 3 && std::string(argv[1]) == "-p" &&
argv[2] != nullptr)
{
- pid = std::stoi(argv[2]);
- kDebugger.Attach(pid);
+ kPID = std::stoi(argv[2]);
+ kDebugger.Attach(kPID);
}
::signal(SIGINT, DebuggerCtrlCHandler);
@@ -76,16 +80,16 @@ LIBCOMPILER_MODULE(DebuggerPOSIX)
std::cout << "[?] Enter a PID to attach on: ";
std::getline(std::cin, cmd);
- pid = std::stoi(cmd.c_str());
+ kPID = std::stoi(cmd.c_str());
- pfd::notify("Debugger Event", "Attach process: " + std::to_string(pid));
+ pfd::notify("Debugger Event", "Attach process: " + std::to_string(kPID));
- kDebugger.Attach(pid);
+ kDebugger.Attach(kPID);
}
if (cmd == "exit")
{
- if (pid > 0)
+ if (kPID > 0)
kDebugger.Detach();
break;