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(find LibMain)
|
||||||
target_link_libraries(flock LibMain)
|
target_link_libraries(flock LibMain)
|
||||||
target_link_libraries(fortune 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(gml-format LibGUI)
|
||||||
target_link_libraries(grep LibRegex)
|
target_link_libraries(grep LibRegex)
|
||||||
target_link_libraries(gunzip LibCompress)
|
target_link_libraries(gunzip LibCompress)
|
||||||
|
|
|
@ -11,12 +11,13 @@
|
||||||
#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 <LibCore/File.h>
|
||||||
|
#include <LibCore/System.h>
|
||||||
#include <LibDebug/DebugSession.h>
|
#include <LibDebug/DebugSession.h>
|
||||||
#include <LibELF/Image.h>
|
#include <LibELF/Image.h>
|
||||||
|
#include <LibMain/Main.h>
|
||||||
#include <LibX86/Disassembler.h>
|
#include <LibX86/Disassembler.h>
|
||||||
#include <LibX86/Instruction.h>
|
#include <LibX86/Instruction.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <syscall.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) {
|
for (size_t i = 0; i < depth; ++i) {
|
||||||
out(" ");
|
out(" ");
|
||||||
}
|
}
|
||||||
const char* begin_color = g_should_output_color ? "\033[34;1m" : "";
|
StringView begin_color = g_should_output_color ? "\033[34;1m"sv : ""sv;
|
||||||
const char* end_color = g_should_output_color ? "\033[0m" : "";
|
StringView end_color = g_should_output_color ? "\033[0m"sv : ""sv;
|
||||||
#if ARCH(I386)
|
#if ARCH(I386)
|
||||||
outln("=> {}SC_{}({:#x}, {:#x}, {:#x}){}",
|
outln("=> {}SC_{}({:#x}, {:#x}, {:#x}){}",
|
||||||
begin_color,
|
begin_color,
|
||||||
|
@ -95,22 +96,19 @@ static NonnullOwnPtr<HashMap<void*, X86::Instruction>> instrument_code()
|
||||||
return instrumented;
|
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) {
|
TRY(Core::System::pledge("stdio proc exec rpath sigaction ptrace"));
|
||||||
perror("pledge");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isatty(STDOUT_FILENO))
|
if (isatty(STDOUT_FILENO))
|
||||||
g_should_output_color = true;
|
g_should_output_color = true;
|
||||||
|
|
||||||
const char* command = nullptr;
|
StringView command;
|
||||||
Core::ArgsParser args_parser;
|
Core::ArgsParser args_parser;
|
||||||
args_parser.add_positional_argument(command,
|
args_parser.add_positional_argument(command,
|
||||||
"The program to be traced, along with its arguments",
|
"The program to be traced, along with its arguments",
|
||||||
"program", Core::ArgsParser::Required::Yes);
|
"program", Core::ArgsParser::Required::Yes);
|
||||||
args_parser.parse(argc, argv);
|
args_parser.parse(arguments);
|
||||||
|
|
||||||
auto result = Debug::DebugSession::exec_and_attach(command);
|
auto result = Debug::DebugSession::exec_and_attach(command);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
|
@ -124,7 +122,7 @@ int main(int argc, char** argv)
|
||||||
struct sigaction sa;
|
struct sigaction sa;
|
||||||
memset(&sa, 0, sizeof(struct sigaction));
|
memset(&sa, 0, sizeof(struct sigaction));
|
||||||
sa.sa_handler = handle_sigint;
|
sa.sa_handler = handle_sigint;
|
||||||
sigaction(SIGINT, &sa, nullptr);
|
TRY(Core::System::sigaction(SIGINT, &sa, nullptr));
|
||||||
|
|
||||||
size_t depth = 0;
|
size_t depth = 0;
|
||||||
bool new_function = true;
|
bool new_function = true;
|
||||||
|
@ -168,4 +166,6 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
return Debug::DebugSession::DebugDecision::SingleStep;
|
return Debug::DebugSession::DebugDecision::SingleStep;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue