From db1b67e88a1ff9758b3a1cb58e99b35330e4b038 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 27 Jul 2020 18:56:19 +0200 Subject: [PATCH] UserspaceEmulator: Set the process and thread name to "(UE) Executable" This makes it much easier to see who's who when running multiple emulators at the same time. :^) --- DevTools/UserspaceEmulator/CMakeLists.txt | 2 +- DevTools/UserspaceEmulator/main.cpp | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/DevTools/UserspaceEmulator/CMakeLists.txt b/DevTools/UserspaceEmulator/CMakeLists.txt index cd41cd61817..afa694ae59f 100644 --- a/DevTools/UserspaceEmulator/CMakeLists.txt +++ b/DevTools/UserspaceEmulator/CMakeLists.txt @@ -10,4 +10,4 @@ set(SOURCES ) serenity_bin(UserspaceEmulator) -target_link_libraries(UserspaceEmulator LibX86 LibDebug LibCore) +target_link_libraries(UserspaceEmulator LibX86 LibDebug LibCore LibPthread) diff --git a/DevTools/UserspaceEmulator/main.cpp b/DevTools/UserspaceEmulator/main.cpp index 82d90a9d1c1..9d2e5018a13 100644 --- a/DevTools/UserspaceEmulator/main.cpp +++ b/DevTools/UserspaceEmulator/main.cpp @@ -26,11 +26,15 @@ #include "Emulator.h" #include "SoftCPU.h" +#include #include #include +#include #include #include #include +#include +#include int main(int argc, char** argv, char** env) { @@ -64,5 +68,17 @@ int main(int argc, char** argv, char** env) if (!emulator.load_elf()) return 1; + StringBuilder builder; + builder.append("(UE) "); + builder.append(LexicalPath(arguments[0]).basename()); + if (set_process_name(builder.string_view().characters_without_null_termination(), builder.string_view().length()) < 0) { + perror("set_process_name"); + return 1; + } + int rc = pthread_setname_np(pthread_self(), builder.to_string().characters()); + if (rc != 0) { + fprintf(stderr, "pthread_setname_np: %s\n", strerror(rc)); + return 1; + } return emulator.exec(); }