LibWebView+UI: Allow debugging any helper process

This removes the --debug-web-content flag, and replaces it with a
--debug-process=<process-name> flag. For example:

    ladybird --debug-process=WebContent
    ladybird --debug-process=RequestServer

This allows attaching gdb to any helper process.
This commit is contained in:
Timothy Flynn 2024-08-01 07:03:03 -04:00 committed by Andreas Kling
parent bbc89a383d
commit 7106a7bd58
Notes: github-actions[bot] 2024-08-01 13:41:42 +00:00
6 changed files with 35 additions and 12 deletions

View file

@ -18,6 +18,9 @@ static ErrorOr<NonnullRefPtr<ClientType>> launch_server_process(
WebView::EnableCallgrindProfiling enable_callgrind_profiling,
ClientArguments&&... client_arguments)
{
auto process_type = WebView::process_type_from_name(server_name);
auto const& chrome_options = WebView::Application::chrome_options();
if (enable_callgrind_profiling == WebView::EnableCallgrindProfiling::Yes) {
arguments.prepend({
"--tool=callgrind"sv,
@ -26,6 +29,9 @@ static ErrorOr<NonnullRefPtr<ClientType>> launch_server_process(
});
}
if (chrome_options.debug_helper_process == process_type)
arguments.append("--wait-for-debugger"sv);
for (auto [i, path] : enumerate(candidate_server_paths)) {
Core::ProcessSpawnOptions options { .name = server_name, .arguments = arguments };
@ -45,7 +51,7 @@ static ErrorOr<NonnullRefPtr<ClientType>> launch_server_process(
if constexpr (requires { process.client->set_pid(pid_t {}); })
process.client->set_pid(process.process.pid());
WebView::Application::the().add_child_process(WebView::Process { WebView::process_type_from_name(server_name), process.client, move(process.process) });
WebView::Application::the().add_child_process(WebView::Process { process_type, process.client, move(process.process) });
if (enable_callgrind_profiling == WebView::EnableCallgrindProfiling::Yes) {
dbgln();
@ -89,8 +95,6 @@ ErrorOr<NonnullRefPtr<WebView::WebContentClient>> launch_web_content_process(
arguments.append("--layout-test-mode"sv);
if (web_content_options.use_lagom_networking == WebView::UseLagomNetworking::Yes)
arguments.append("--use-lagom-networking"sv);
if (web_content_options.wait_for_debugger == WebView::WaitForDebugger::Yes)
arguments.append("--wait-for-debugger"sv);
if (web_content_options.log_all_js_exceptions == WebView::LogAllJSExceptions::Yes)
arguments.append("--log-all-js-exceptions"sv);
if (web_content_options.enable_idl_tracing == WebView::EnableIDLTracing::Yes)

View file

@ -9,6 +9,7 @@
#include <ImageDecoder/ConnectionFromClient.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/EventLoop.h>
#include <LibCore/Process.h>
#include <LibIPC/SingleServer.h>
#include <LibMain/Main.h>
@ -22,9 +23,15 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
Core::ArgsParser args_parser;
StringView mach_server_name;
bool wait_for_debugger = false;
args_parser.add_option(mach_server_name, "Mach server name", "mach-server-name", 0, "mach_server_name");
args_parser.add_option(wait_for_debugger, "Wait for debugger", "wait-for-debugger");
args_parser.parse(arguments);
if (wait_for_debugger)
Core::Process::wait_for_debugger_and_break();
Core::EventLoop event_loop;
#if defined(AK_OS_MACOS)

View file

@ -10,6 +10,7 @@
#include <LibCore/ArgsParser.h>
#include <LibCore/EventLoop.h>
#include <LibCore/LocalServer.h>
#include <LibCore/Process.h>
#include <LibCore/System.h>
#include <LibFileSystem/FileSystem.h>
#include <LibIPC/SingleServer.h>
@ -38,13 +39,18 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
StringView serenity_resource_root;
Vector<ByteString> certificates;
StringView mach_server_name;
bool wait_for_debugger = false;
Core::ArgsParser args_parser;
args_parser.add_option(certificates, "Path to a certificate file", "certificate", 'C', "certificate");
args_parser.add_option(serenity_resource_root, "Absolute path to directory for serenity resources", "serenity-resource-root", 'r', "serenity-resource-root");
args_parser.add_option(mach_server_name, "Mach server name", "mach-server-name", 0, "mach_server_name");
args_parser.add_option(wait_for_debugger, "Wait for debugger", "wait-for-debugger");
args_parser.parse(arguments);
if (wait_for_debugger)
Core::Process::wait_for_debugger_and_break();
// Ensure the certificates are read out here.
if (certificates.is_empty())
certificates.append(TRY(find_certificates(serenity_resource_root)));

View file

@ -10,6 +10,7 @@
#include <LibCore/ArgsParser.h>
#include <LibCore/EventLoop.h>
#include <LibCore/LocalServer.h>
#include <LibCore/Process.h>
#include <LibCore/StandardPaths.h>
#include <LibCore/System.h>
#include <LibFileSystem/FileSystem.h>
@ -41,14 +42,19 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
StringView serenity_resource_root;
Vector<ByteString> certificates;
bool use_lagom_networking { false };
bool wait_for_debugger = false;
Core::ArgsParser args_parser;
args_parser.add_option(request_server_socket, "File descriptor of the request server socket", "request-server-socket", 's', "request-server-socket");
args_parser.add_option(serenity_resource_root, "Absolute path to directory for serenity resources", "serenity-resource-root", 'r', "serenity-resource-root");
args_parser.add_option(use_lagom_networking, "Enable Lagom servers for networking", "use-lagom-networking");
args_parser.add_option(certificates, "Path to a certificate file", "certificate", 'C', "certificate");
args_parser.add_option(wait_for_debugger, "Wait for debugger", "wait-for-debugger");
args_parser.parse(arguments);
if (wait_for_debugger)
Core::Process::wait_for_debugger_and_break();
#if defined(HAVE_QT)
QCoreApplication app(arguments.argc, arguments.argv);
Core::EventLoopManager::install(*new Ladybird::EventLoopManagerQt);

View file

@ -38,9 +38,9 @@ void Application::initialize(Main::Arguments const& arguments, URL::URL new_tab_
bool force_new_process = false;
bool allow_popups = false;
bool disable_sql_database = false;
Optional<StringView> debug_process;
Optional<StringView> webdriver_content_ipc_path;
bool enable_callgrind_profiling = false;
bool debug_web_content = false;
bool log_all_js_exceptions = false;
bool enable_idl_tracing = false;
bool enable_http_cache = false;
@ -54,9 +54,9 @@ void Application::initialize(Main::Arguments const& arguments, URL::URL new_tab_
args_parser.add_option(force_new_process, "Force creation of new browser/chrome process", "force-new-process");
args_parser.add_option(allow_popups, "Disable popup blocking by default", "allow-popups");
args_parser.add_option(disable_sql_database, "Disable SQL database", "disable-sql-database");
args_parser.add_option(debug_process, "Wait for a debugger to attach to the given process name (WebContent, RequestServer, etc.)", "debug-process", 0, "process-name");
args_parser.add_option(webdriver_content_ipc_path, "Path to WebDriver IPC for WebContent", "webdriver-content-path", 0, "path", Core::ArgsParser::OptionHideMode::CommandLineAndMarkdown);
args_parser.add_option(enable_callgrind_profiling, "Enable Callgrind profiling", "enable-callgrind-profiling", 'P');
args_parser.add_option(debug_web_content, "Wait for debugger to attach to WebContent", "debug-web-content");
args_parser.add_option(log_all_js_exceptions, "Log all JavaScript exceptions", "log-all-js-exceptions");
args_parser.add_option(enable_idl_tracing, "Enable IDL tracing", "enable-idl-tracing");
args_parser.add_option(enable_http_cache, "Enable HTTP cache", "enable-http-cache");
@ -65,6 +65,10 @@ void Application::initialize(Main::Arguments const& arguments, URL::URL new_tab_
create_platform_arguments(args_parser);
args_parser.parse(arguments);
Optional<ProcessType> debug_process_type;
if (debug_process.has_value())
debug_process_type = process_type_from_name(*debug_process);
m_chrome_options = {
.urls = sanitize_urls(raw_urls, new_tab_page_url),
.raw_urls = move(raw_urls),
@ -74,6 +78,7 @@ void Application::initialize(Main::Arguments const& arguments, URL::URL new_tab_
.force_new_process = force_new_process ? ForceNewProcess::Yes : ForceNewProcess::No,
.allow_popups = allow_popups ? AllowPopups::Yes : AllowPopups::No,
.disable_sql_database = disable_sql_database ? DisableSQLDatabase::Yes : DisableSQLDatabase::No,
.debug_helper_process = move(debug_process_type),
};
if (webdriver_content_ipc_path.has_value())
@ -83,7 +88,6 @@ void Application::initialize(Main::Arguments const& arguments, URL::URL new_tab_
.command_line = MUST(String::join(' ', arguments.strings)),
.executable_path = MUST(String::from_byte_string(MUST(Core::System::current_executable_path()))),
.enable_callgrind_profiling = enable_callgrind_profiling ? EnableCallgrindProfiling::Yes : EnableCallgrindProfiling::No,
.wait_for_debugger = debug_web_content ? WaitForDebugger::Yes : WaitForDebugger::No,
.log_all_js_exceptions = log_all_js_exceptions ? LogAllJSExceptions::Yes : LogAllJSExceptions::No,
.enable_idl_tracing = enable_idl_tracing ? EnableIDLTracing::Yes : EnableIDLTracing::No,
.enable_http_cache = enable_http_cache ? EnableHTTPCache::Yes : EnableHTTPCache::No,

View file

@ -11,6 +11,7 @@
#include <AK/String.h>
#include <AK/Vector.h>
#include <LibURL/URL.h>
#include <LibWebView/ProcessType.h>
namespace WebView {
@ -43,6 +44,7 @@ struct ChromeOptions {
ForceNewProcess force_new_process { ForceNewProcess::No };
AllowPopups allow_popups { AllowPopups::No };
DisableSQLDatabase disable_sql_database { DisableSQLDatabase::No };
Optional<ProcessType> debug_helper_process {};
Optional<ByteString> webdriver_content_ipc_path {};
};
@ -61,11 +63,6 @@ enum class UseLagomNetworking {
Yes,
};
enum class WaitForDebugger {
No,
Yes,
};
enum class LogAllJSExceptions {
No,
Yes,
@ -93,7 +90,6 @@ struct WebContentOptions {
EnableCallgrindProfiling enable_callgrind_profiling { EnableCallgrindProfiling::No };
IsLayoutTestMode is_layout_test_mode { IsLayoutTestMode::No };
UseLagomNetworking use_lagom_networking { UseLagomNetworking::Yes };
WaitForDebugger wait_for_debugger { WaitForDebugger::No };
LogAllJSExceptions log_all_js_exceptions { LogAllJSExceptions::No };
EnableIDLTracing enable_idl_tracing { EnableIDLTracing::No };
EnableHTTPCache enable_http_cache { EnableHTTPCache::No };