mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:47:45 +00:00
functrace: use Core::ArgsParser
This commit is contained in:
parent
bedce69b23
commit
10bdb6f33b
1 changed files with 9 additions and 16 deletions
|
@ -34,6 +34,7 @@
|
||||||
#include <AK/kmalloc.h>
|
#include <AK/kmalloc.h>
|
||||||
#include <Kernel/Syscall.h>
|
#include <Kernel/Syscall.h>
|
||||||
#include <LibC/sys/arch/i386/regs.h>
|
#include <LibC/sys/arch/i386/regs.h>
|
||||||
|
#include <LibCore/ArgsParser.h>
|
||||||
#include <LibCore/File.h>
|
#include <LibCore/File.h>
|
||||||
#include <LibDebug/DebugSession.h>
|
#include <LibDebug/DebugSession.h>
|
||||||
#include <LibELF/Image.h>
|
#include <LibELF/Image.h>
|
||||||
|
@ -46,12 +47,6 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
static int usage()
|
|
||||||
{
|
|
||||||
printf("usage: functrace [command...]\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
OwnPtr<DebugSession> g_debug_session;
|
OwnPtr<DebugSession> g_debug_session;
|
||||||
|
|
||||||
static void handle_sigint(int)
|
static void handle_sigint(int)
|
||||||
|
@ -120,18 +115,16 @@ int main(int argc, char** argv)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc == 1)
|
const char* command = nullptr;
|
||||||
return usage();
|
Core::ArgsParser args_parser;
|
||||||
|
args_parser.add_positional_argument(command,
|
||||||
|
"The program to be traced, along with its arguments",
|
||||||
|
"program", Core::ArgsParser::Required::Yes);
|
||||||
|
args_parser.parse(argc, argv);
|
||||||
|
|
||||||
StringBuilder command;
|
auto result = DebugSession::exec_and_attach(command);
|
||||||
command.append(argv[1]);
|
|
||||||
for (int i = 2; i < argc; ++i) {
|
|
||||||
command.appendf("%s ", argv[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto result = DebugSession::exec_and_attach(command.to_string());
|
|
||||||
if (!result) {
|
if (!result) {
|
||||||
fprintf(stderr, "Failed to start debugging session for: \"%s\"\n", command.to_string().characters());
|
fprintf(stderr, "Failed to start debugging session for: \"%s\"\n", command);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
g_debug_session = result.release_nonnull();
|
g_debug_session = result.release_nonnull();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue