Skip to content

Commit ed971f1

Browse files
ldm5180linusg
authored andcommitted
Applications: Port Debugger to LibMain
1 parent e5d1785 commit ed971f1

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

Userland/Applications/Debugger/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ set(SOURCES
88
)
99

1010
serenity_bin(Debugger)
11-
target_link_libraries(Debugger LibCore LibDebug LibX86 LibLine)
11+
target_link_libraries(Debugger LibCore LibDebug LibLine LibMain LibX86)

Userland/Applications/Debugger/main.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* Copyright (c) 2020, Itamar S. <itamar8910@gmail.com>
3+
* Copyright (c) 2022, the SerenityOS developers.
34
*
45
* SPDX-License-Identifier: BSD-2-Clause
56
*/
@@ -9,11 +10,14 @@
910
#include <AK/OwnPtr.h>
1011
#include <AK/Platform.h>
1112
#include <AK/StringBuilder.h>
13+
#include <AK/Try.h>
1214
#include <LibC/sys/arch/i386/regs.h>
1315
#include <LibCore/ArgsParser.h>
16+
#include <LibCore/System.h>
1417
#include <LibDebug/DebugInfo.h>
1518
#include <LibDebug/DebugSession.h>
1619
#include <LibLine/Editor.h>
20+
#include <LibMain/Main.h>
1721
#include <LibX86/Disassembler.h>
1822
#include <LibX86/Instruction.h>
1923
#include <signal.h>
@@ -204,21 +208,18 @@ static void print_help()
204208
"x <address> - examine dword in memory\n");
205209
}
206210

207-
int main(int argc, char** argv)
211+
ErrorOr<int> serenity_main(Main::Arguments arguments)
208212
{
209213
editor = Line::Editor::construct();
210214

211-
if (pledge("stdio proc ptrace exec rpath tty sigaction cpath unix", nullptr) < 0) {
212-
perror("pledge");
213-
return 1;
214-
}
215+
TRY(Core::System::pledge("stdio proc ptrace exec rpath tty sigaction cpath unix", nullptr));
215216

216217
const char* command = nullptr;
217218
Core::ArgsParser args_parser;
218219
args_parser.add_positional_argument(command,
219220
"The program to be debugged, along with its arguments",
220221
"program", Core::ArgsParser::Required::Yes);
221-
args_parser.parse(argc, argv);
222+
args_parser.parse(arguments);
222223

223224
auto result = Debug::DebugSession::exec_and_attach(command);
224225
if (!result) {
@@ -230,7 +231,7 @@ int main(int argc, char** argv)
230231
struct sigaction sa {
231232
};
232233
sa.sa_handler = handle_sigint;
233-
sigaction(SIGINT, &sa, nullptr);
234+
TRY(Core::System::sigaction(SIGINT, &sa, nullptr));
234235

235236
Debug::DebugInfo::SourcePosition previous_source_position;
236237
bool in_step_line = false;
@@ -331,4 +332,6 @@ int main(int argc, char** argv)
331332
return decision.value();
332333
}
333334
});
335+
336+
return 0;
334337
}

0 commit comments

Comments
 (0)