mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:17:36 +00:00
LibCore: Implement Process::is_being_debugged for macOS
The wait_for_debugger_and_break helper now works on macOS with this change, tested on lldb 14.
This commit is contained in:
parent
35c45a94d3
commit
fc71403842
1 changed files with 22 additions and 3 deletions
|
@ -17,9 +17,11 @@
|
||||||
#include <spawn.h>
|
#include <spawn.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#ifdef AK_OS_SERENITY
|
#if defined(AK_OS_SERENITY)
|
||||||
# include <serenity.h>
|
# include <serenity.h>
|
||||||
# include <syscall.h>
|
# include <syscall.h>
|
||||||
|
#elif defined(AK_OS_BSD_GENERIC)
|
||||||
|
# include <sys/sysctl.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
|
@ -147,7 +149,7 @@ ErrorOr<void> Process::set_name([[maybe_unused]] StringView name, [[maybe_unused
|
||||||
|
|
||||||
ErrorOr<bool> Process::is_being_debugged()
|
ErrorOr<bool> Process::is_being_debugged()
|
||||||
{
|
{
|
||||||
#ifdef AK_OS_LINUX
|
#if defined(AK_OS_LINUX)
|
||||||
auto unbuffered_status_file = TRY(Core::File::open("/proc/self/status"sv, Core::File::OpenMode::Read));
|
auto unbuffered_status_file = TRY(Core::File::open("/proc/self/status"sv, Core::File::OpenMode::Read));
|
||||||
auto status_file = TRY(Core::InputBufferedFile::create(move(unbuffered_status_file)));
|
auto status_file = TRY(Core::InputBufferedFile::create(move(unbuffered_status_file)));
|
||||||
auto buffer = TRY(ByteBuffer::create_uninitialized(4096));
|
auto buffer = TRY(ByteBuffer::create_uninitialized(4096));
|
||||||
|
@ -160,9 +162,26 @@ ErrorOr<bool> Process::is_being_debugged()
|
||||||
return (tracer_pid != 0UL);
|
return (tracer_pid != 0UL);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
#elif defined(AK_OS_MACOS)
|
||||||
|
// https://developer.apple.com/library/archive/qa/qa1361/_index.html
|
||||||
|
int mib[4] = {};
|
||||||
|
struct kinfo_proc info = {};
|
||||||
|
size_t size = sizeof(info);
|
||||||
|
|
||||||
|
// Initialize mib, which tells sysctl the info we want, in this case
|
||||||
|
// we're looking for information about a specific process ID.
|
||||||
|
mib[0] = CTL_KERN;
|
||||||
|
mib[1] = KERN_PROC;
|
||||||
|
mib[2] = KERN_PROC_PID;
|
||||||
|
mib[3] = getpid();
|
||||||
|
|
||||||
|
if (sysctl(mib, sizeof(mib) / sizeof(*mib), &info, &size, NULL, 0) < 0)
|
||||||
|
return Error::from_syscall("sysctl"sv, -errno);
|
||||||
|
|
||||||
|
// We're being debugged if the P_TRACED flag is set.
|
||||||
|
return ((info.kp_proc.p_flag & P_TRACED) != 0);
|
||||||
#endif
|
#endif
|
||||||
// FIXME: Implement this for more platforms.
|
// FIXME: Implement this for more platforms.
|
||||||
// MacOS version: https://developer.apple.com/library/archive/qa/qa1361/_index.html
|
|
||||||
return Error::from_string_view("Platform does not support checking for debugger"sv);
|
return Error::from_string_view("Platform does not support checking for debugger"sv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue