mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
LibDebug: Add optional setup_child() callback to debugger
If set, this callback gets called right after fork() in the child process. It can be used by the caller if it wants to perform some logic in the child process before it starts executing the debuggee program.
This commit is contained in:
parent
0cea8d1310
commit
a02d8e5710
Notes:
sideshowbarker
2024-07-17 22:22:44 +09:00
Author: https://github.com/itamar8910 Commit: https://github.com/SerenityOS/serenity/commit/a02d8e57101 Pull-request: https://github.com/SerenityOS/serenity/pull/11335
2 changed files with 13 additions and 2 deletions
|
@ -53,7 +53,9 @@ void DebugSession::for_each_loaded_library(Function<IterationDecision(LoadedLibr
|
|||
}
|
||||
}
|
||||
|
||||
OwnPtr<DebugSession> DebugSession::exec_and_attach(String const& command, String source_root)
|
||||
OwnPtr<DebugSession> DebugSession::exec_and_attach(String const& command,
|
||||
String source_root,
|
||||
Function<ErrorOr<void>()> setup_child)
|
||||
{
|
||||
auto pid = fork();
|
||||
|
||||
|
@ -63,6 +65,14 @@ OwnPtr<DebugSession> DebugSession::exec_and_attach(String const& command, String
|
|||
}
|
||||
|
||||
if (!pid) {
|
||||
|
||||
if (setup_child) {
|
||||
if (setup_child().is_error()) {
|
||||
perror("DebugSession::setup_child");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
if (ptrace(PT_TRACE_ME, 0, 0, 0) < 0) {
|
||||
perror("PT_TRACE_ME");
|
||||
exit(1);
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/Demangle.h>
|
||||
#include <AK/Function.h>
|
||||
#include <AK/HashMap.h>
|
||||
#include <AK/NonnullRefPtr.h>
|
||||
#include <AK/Optional.h>
|
||||
|
@ -26,7 +27,7 @@ namespace Debug {
|
|||
|
||||
class DebugSession : public ProcessInspector {
|
||||
public:
|
||||
static OwnPtr<DebugSession> exec_and_attach(String const& command, String source_root = {});
|
||||
static OwnPtr<DebugSession> exec_and_attach(String const& command, String source_root = {}, Function<ErrorOr<void>()> setup_child = {});
|
||||
|
||||
virtual ~DebugSession() override;
|
||||
|
||||
|
|
Loading…
Reference in a new issue