summaryrefslogtreecommitdiffhomepage
path: root/dev/LibDebugger/src/DebuggerEnginePOSIX.cc
blob: e8a394efb628a0e0343bd4aab1516c47061d8b66 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/***
	(C) 2025 Amlal El Mahrouss
 */

#include <LibCompiler/Defines.h>
#include <LibDebugger/IDebuggerEngine.h>

#ifndef _WIN32

LIBCOMPILER_MODULE(DebuggerPOSIX)
{
	LibDebugger::IDebuggerEngine debugger;
	pid_t				   pid = 0L;

	if (argc >= 3 && std::string(argv[1]) == "-p" &&
		argv[2] != nullptr)
	{
		pid = std::stoi(argv[2]);
		debugger.Attach(pid);
	}

	while (YES)
	{
		std::string cmd;
		std::getline(std::cin, cmd);

		if (cmd == "c" ||
			cmd == "cont")
			debugger.ContinueExecution();

		if (cmd == "d" ||
			cmd == "detach")
			debugger.Detach();

		if (cmd == "attach")
		{
			std::cout << "[?] Enter a PID to attach on: ";

			std::getline(std::cin, cmd);
			pid = std::stoi(cmd.c_str());

			debugger.Attach(pid);
		}

		if (cmd == "exit")
		{
			if (pid > 0)
				debugger.Detach();

			break;
		}

		if (cmd == "break" ||
			cmd == "b")
		{
			std::cout << "[?] Enter an address to add a breakpoint on: ";

			std::getline(std::cin, cmd);

			LibDebugger::CAddr breakpoint_addr = reinterpret_cast<LibDebugger::CAddr>(std::stoul(cmd.c_str(), nullptr, 16));

			if (breakpoint_addr)
				debugger.SetBreakpoint(breakpoint_addr);
		}
	}

	return 0;
}

#endif