/* * Copyright (c) 2020, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ #include "Emulator.h" #include #include #include #include #include #include #include #include #include bool g_report_to_debug = false; int main(int argc, char** argv, char** env) { Vector arguments; Core::ArgsParser parser; parser.add_option(g_report_to_debug, "Write reports to the debug log", "report-to-debug", 0); parser.add_positional_argument(arguments, "Command to emulate", "command"); parser.parse(argc, argv); auto executable_path = Core::find_executable_in_path(arguments[0]); if (executable_path.is_empty()) { executable_path = Core::File::real_path_for(arguments[0]); if (executable_path.is_empty()) { reportln("Cannot find executable for '{}'.", executable_path); return 1; } } Vector environment; for (int i = 0; env[i]; ++i) { environment.append(env[i]); } // FIXME: It might be nice to tear down the emulator properly. auto& emulator = *new UserspaceEmulator::Emulator(executable_path, arguments, environment); 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) { reportln("pthread_setname_np: {}", strerror(rc)); return 1; } return emulator.exec(); }