mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
functrace: Port to LibMain and move away from raw C strings
Ports to LibMain and uses StringView more (rather than raw C strings).
This commit is contained in:
parent
160f3224a5
commit
0edceb91c4
Notes:
sideshowbarker
2024-07-17 22:43:44 +09:00
Author: https://github.com/kennethmyhra Commit: https://github.com/SerenityOS/serenity/commit/0edceb91c45 Pull-request: https://github.com/SerenityOS/serenity/pull/11253 Reviewed-by: https://github.com/alimpfard Reviewed-by: https://github.com/bgianfo ✅
2 changed files with 12 additions and 12 deletions
|
@ -92,7 +92,7 @@ target_link_libraries(file LibGfx LibIPC LibCompress LibMain)
|
|||
target_link_libraries(find LibMain)
|
||||
target_link_libraries(flock LibMain)
|
||||
target_link_libraries(fortune LibMain)
|
||||
target_link_libraries(functrace LibDebug LibX86)
|
||||
target_link_libraries(functrace LibDebug LibX86 LibMain)
|
||||
target_link_libraries(gml-format LibGUI)
|
||||
target_link_libraries(grep LibRegex)
|
||||
target_link_libraries(gunzip LibCompress)
|
||||
|
|
|
@ -11,12 +11,13 @@
|
|||
#include <LibC/sys/arch/i386/regs.h>
|
||||
#include <LibCore/ArgsParser.h>
|
||||
#include <LibCore/File.h>
|
||||
#include <LibCore/System.h>
|
||||
#include <LibDebug/DebugSession.h>
|
||||
#include <LibELF/Image.h>
|
||||
#include <LibMain/Main.h>
|
||||
#include <LibX86/Disassembler.h>
|
||||
#include <LibX86/Instruction.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <syscall.h>
|
||||
|
@ -46,8 +47,8 @@ static void print_syscall(PtraceRegisters& regs, size_t depth)
|
|||
for (size_t i = 0; i < depth; ++i) {
|
||||
out(" ");
|
||||
}
|
||||
const char* begin_color = g_should_output_color ? "\033[34;1m" : "";
|
||||
const char* end_color = g_should_output_color ? "\033[0m" : "";
|
||||
StringView begin_color = g_should_output_color ? "\033[34;1m"sv : ""sv;
|
||||
StringView end_color = g_should_output_color ? "\033[0m"sv : ""sv;
|
||||
#if ARCH(I386)
|
||||
outln("=> {}SC_{}({:#x}, {:#x}, {:#x}){}",
|
||||
begin_color,
|
||||
|
@ -95,22 +96,19 @@ static NonnullOwnPtr<HashMap<void*, X86::Instruction>> instrument_code()
|
|||
return instrumented;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
{
|
||||
if (pledge("stdio proc exec rpath sigaction ptrace", nullptr) < 0) {
|
||||
perror("pledge");
|
||||
return 1;
|
||||
}
|
||||
TRY(Core::System::pledge("stdio proc exec rpath sigaction ptrace"));
|
||||
|
||||
if (isatty(STDOUT_FILENO))
|
||||
g_should_output_color = true;
|
||||
|
||||
const char* command = nullptr;
|
||||
StringView command;
|
||||
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);
|
||||
args_parser.parse(arguments);
|
||||
|
||||
auto result = Debug::DebugSession::exec_and_attach(command);
|
||||
if (!result) {
|
||||
|
@ -124,7 +122,7 @@ int main(int argc, char** argv)
|
|||
struct sigaction sa;
|
||||
memset(&sa, 0, sizeof(struct sigaction));
|
||||
sa.sa_handler = handle_sigint;
|
||||
sigaction(SIGINT, &sa, nullptr);
|
||||
TRY(Core::System::sigaction(SIGINT, &sa, nullptr));
|
||||
|
||||
size_t depth = 0;
|
||||
bool new_function = true;
|
||||
|
@ -168,4 +166,6 @@ int main(int argc, char** argv)
|
|||
|
||||
return Debug::DebugSession::DebugDecision::SingleStep;
|
||||
});
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue