mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-27 06:48:49 +00:00
Userland: Add strace parameter for output log file
This commit is contained in:
parent
b71edba06d
commit
3eeb00b003
Notes:
sideshowbarker
2024-07-19 00:38:28 +09:00
Author: https://github.com/ccapitalK
Commit: 3eeb00b003
Pull-request: https://github.com/SerenityOS/serenity/pull/4519
1 changed files with 16 additions and 2 deletions
|
@ -30,6 +30,7 @@
|
||||||
#include <Kernel/API/Syscall.h>
|
#include <Kernel/API/Syscall.h>
|
||||||
#include <LibC/sys/arch/i386/regs.h>
|
#include <LibC/sys/arch/i386/regs.h>
|
||||||
#include <LibCore/ArgsParser.h>
|
#include <LibCore/ArgsParser.h>
|
||||||
|
#include <LibCore/File.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -54,18 +55,31 @@ int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
Vector<const char*> child_argv;
|
Vector<const char*> child_argv;
|
||||||
|
|
||||||
|
const char* output_filename = nullptr;
|
||||||
|
auto trace_file = Core::File::standard_output();
|
||||||
|
|
||||||
Core::ArgsParser parser;
|
Core::ArgsParser parser;
|
||||||
parser.set_general_help(
|
parser.set_general_help(
|
||||||
"Trace all syscalls and their result.");
|
"Trace all syscalls and their result.");
|
||||||
parser.add_option(g_pid, "Trace the given PID", "pid", 'p', "pid");
|
parser.add_option(g_pid, "Trace the given PID", "pid", 'p', "pid");
|
||||||
|
parser.add_option(output_filename, "Filename to write output to", "output", 'o', "output");
|
||||||
parser.add_positional_argument(child_argv, "Arguments to exec", "argument", Core::ArgsParser::Required::No);
|
parser.add_positional_argument(child_argv, "Arguments to exec", "argument", Core::ArgsParser::Required::No);
|
||||||
|
|
||||||
parser.parse(argc, argv);
|
parser.parse(argc, argv);
|
||||||
|
|
||||||
|
if (output_filename != nullptr) {
|
||||||
|
auto open_result = Core::File::open(output_filename, Core::IODevice::OpenMode::WriteOnly);
|
||||||
|
if (open_result.is_error()) {
|
||||||
|
outln(stderr, "Failed to open output file: {}", open_result.error());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
trace_file = open_result.value();
|
||||||
|
}
|
||||||
|
|
||||||
int status;
|
int status;
|
||||||
if (g_pid == -1) {
|
if (g_pid == -1) {
|
||||||
if (child_argv.is_empty()) {
|
if (child_argv.is_empty()) {
|
||||||
fprintf(stderr, "strace: Expected either a pid or some arguments\n");
|
outln(stderr, "strace: Expected either a pid or some arguments\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,7 +159,7 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
u32 res = regs.eax;
|
u32 res = regs.eax;
|
||||||
|
|
||||||
fprintf(stderr, "%s(0x%x, 0x%x, 0x%x)\t=%d\n",
|
trace_file->printf("%s(0x%x, 0x%x, 0x%x)\t=%d\n",
|
||||||
Syscall::to_string(
|
Syscall::to_string(
|
||||||
(Syscall::Function)syscall_index),
|
(Syscall::Function)syscall_index),
|
||||||
arg1,
|
arg1,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue