From 6e437674f787452abfdf83626dae93c8461f09bb Mon Sep 17 00:00:00 2001 From: Christian Prochaska Date: Tue, 12 Mar 2024 18:27:07 +0100 Subject: [PATCH] gems: add dbg_download Fixes #5143 --- repos/gems/recipes/pkg/dbg_download/README | 2 + repos/gems/recipes/pkg/dbg_download/archives | 3 + repos/gems/recipes/pkg/dbg_download/hash | 1 + repos/gems/recipes/pkg/dbg_download/runtime | 145 +++++++++++++++ .../recipes/pkg/sculpt_distribution/archives | 1 + .../gems/recipes/src/dbg_download/content.mk | 2 + repos/gems/recipes/src/dbg_download/hash | 1 + repos/gems/recipes/src/dbg_download/used_apis | 4 + repos/gems/sculpt/default-pc.sculpt | 2 +- .../gems/sculpt/launcher/download_debug_info | 19 ++ repos/gems/src/app/dbg_download/main.cc | 175 ++++++++++++++++++ repos/gems/src/app/dbg_download/target.mk | 3 + 12 files changed, 357 insertions(+), 1 deletion(-) create mode 100644 repos/gems/recipes/pkg/dbg_download/README create mode 100644 repos/gems/recipes/pkg/dbg_download/archives create mode 100644 repos/gems/recipes/pkg/dbg_download/hash create mode 100644 repos/gems/recipes/pkg/dbg_download/runtime create mode 100644 repos/gems/recipes/src/dbg_download/content.mk create mode 100644 repos/gems/recipes/src/dbg_download/hash create mode 100644 repos/gems/recipes/src/dbg_download/used_apis create mode 100644 repos/gems/sculpt/launcher/download_debug_info create mode 100644 repos/gems/src/app/dbg_download/main.cc create mode 100644 repos/gems/src/app/dbg_download/target.mk diff --git a/repos/gems/recipes/pkg/dbg_download/README b/repos/gems/recipes/pkg/dbg_download/README new file mode 100644 index 0000000000..c80bb2f92b --- /dev/null +++ b/repos/gems/recipes/pkg/dbg_download/README @@ -0,0 +1,2 @@ + + Subsystem for downloading debug info depot content diff --git a/repos/gems/recipes/pkg/dbg_download/archives b/repos/gems/recipes/pkg/dbg_download/archives new file mode 100644 index 0000000000..a4d4c1f545 --- /dev/null +++ b/repos/gems/recipes/pkg/dbg_download/archives @@ -0,0 +1,3 @@ +_/pkg/depot_download +_/src/dbg_download +_/src/vfs_lxip diff --git a/repos/gems/recipes/pkg/dbg_download/hash b/repos/gems/recipes/pkg/dbg_download/hash new file mode 100644 index 0000000000..0135909971 --- /dev/null +++ b/repos/gems/recipes/pkg/dbg_download/hash @@ -0,0 +1 @@ +2023-12-03 6d3ae110891ef272496abf7dfa9217ff2566cf64 diff --git a/repos/gems/recipes/pkg/dbg_download/runtime b/repos/gems/recipes/pkg/dbg_download/runtime new file mode 100644 index 0000000000..95f77ae340 --- /dev/null +++ b/repos/gems/recipes/pkg/dbg_download/runtime @@ -0,0 +1,145 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/repos/gems/recipes/pkg/sculpt_distribution/archives b/repos/gems/recipes/pkg/sculpt_distribution/archives index b72b783213..429f2839a1 100644 --- a/repos/gems/recipes/pkg/sculpt_distribution/archives +++ b/repos/gems/recipes/pkg/sculpt_distribution/archives @@ -23,3 +23,4 @@ _/pkg/trace_logger _/pkg/mixer _/pkg/dynamic_rom _/pkg/unconfigured_nano3d +_/pkg/dbg_download diff --git a/repos/gems/recipes/src/dbg_download/content.mk b/repos/gems/recipes/src/dbg_download/content.mk new file mode 100644 index 0000000000..1e9e81f847 --- /dev/null +++ b/repos/gems/recipes/src/dbg_download/content.mk @@ -0,0 +1,2 @@ +SRC_DIR = src/app/dbg_download +include $(GENODE_DIR)/repos/base/recipes/src/content.inc diff --git a/repos/gems/recipes/src/dbg_download/hash b/repos/gems/recipes/src/dbg_download/hash new file mode 100644 index 0000000000..641f7f65a9 --- /dev/null +++ b/repos/gems/recipes/src/dbg_download/hash @@ -0,0 +1 @@ +2023-12-05-i 1d3df6ce30d962877acce17d07b09173373116d4 diff --git a/repos/gems/recipes/src/dbg_download/used_apis b/repos/gems/recipes/src/dbg_download/used_apis new file mode 100644 index 0000000000..f9afabe733 --- /dev/null +++ b/repos/gems/recipes/src/dbg_download/used_apis @@ -0,0 +1,4 @@ +base +os +report_session +vfs diff --git a/repos/gems/sculpt/default-pc.sculpt b/repos/gems/sculpt/default-pc.sculpt index 63f8a3bb89..bc48659d3b 100644 --- a/repos/gems/sculpt/default-pc.sculpt +++ b/repos/gems/sculpt/default-pc.sculpt @@ -7,7 +7,7 @@ gpu_drv: intel import: pkg/drivers_managed-pc pkg/pc_wifi src/pc_nic_drv # selection of launcher-menu entries -launcher: vm_fs shared_fs usb_devices_rom +launcher: vm_fs shared_fs usb_devices_rom download_debug_info # selection of accepted depot-package providers depot: genodelabs cnuke alex-ab mstein nfeske cproc chelmuth jschlatow diff --git a/repos/gems/sculpt/launcher/download_debug_info b/repos/gems/sculpt/launcher/download_debug_info new file mode 100644 index 0000000000..9d208a0114 --- /dev/null +++ b/repos/gems/sculpt/launcher/download_debug_info @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/repos/gems/src/app/dbg_download/main.cc b/repos/gems/src/app/dbg_download/main.cc new file mode 100644 index 0000000000..d9512aaf3d --- /dev/null +++ b/repos/gems/src/app/dbg_download/main.cc @@ -0,0 +1,175 @@ +/* + * \brief Component which initiates the download of missing 'bin' and 'dbg' + * depot archives based on the current runtime/monitor configuration + * \author Christian Prochaska + * \date 2023-12-04 + */ + +/* + * Copyright (C) 2023-2024 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU Affero General Public License version 3. + */ + +/* Genode includes */ +#include +#include +#include +#include +#include +#include + +using namespace Genode; + +struct Main +{ + Genode::Env &_env; + Heap _heap { _env.ram(), _env.rm() }; + + Attached_rom_dataspace _config { _env, "config" }; + Attached_rom_dataspace _build_info { _env, "build_info" }; + + Session_label _base_archive { }; + + Root_directory _root_dir { _env, _heap, _config.xml().sub_node("vfs") }; + + static constexpr char const *_runtime_config_path { "/config/managed/runtime" }; + + Watch_handler
_runtime_config_watch_handler { + _env.ep(), _root_dir, _runtime_config_path, + *this, &Main::_handle_runtime_config_update }; + + Expanding_reporter _installation { _env, "installation", "installation" }; + + + void _process_monitor_config(Xml_node const &config, Xml_node const &monitor) + { + _installation.generate([&] (Xml_generator &xml) { + + monitor.for_each_sub_node("policy", [&] (Xml_node const &policy) { + + Session_label policy_label { + policy.attribute_value("label", Session_label::String()) }; + + config.for_each_sub_node("start", [&] (Xml_node const &start) { + + if (start.attribute_value("name", Session_label::String()) != + policy_label) + return; + + start.with_sub_node("route", [&] (Xml_node const &route) { + + route.for_each_sub_node("service", [&] (Xml_node const &service) { + + if (service.attribute_value("name", String<8>()) != "ROM") + return; + + if (!service.has_attribute("label_last")) + return; + + Session_label rom_session_label; + + if (service.attribute_value("label_last", Session_label::String()) == + "ld.lib.so") { + + rom_session_label = { _base_archive, "/ld.lib.so" }; + + } else { + + service.with_sub_node("child", [&] (Xml_node const &child) { + + if (child.attribute_value("name", String<16>()) != + "depot_rom") + return; + + rom_session_label = + child.attribute_value("label", Session_label::String()); + + }, [&] () { + Genode::warning(" XML node not found"); + return; + }); + } + + Vfs::Absolute_path rom_session_label_path { rom_session_label }; + + Vfs::Absolute_path depot_user_path { rom_session_label_path }; + while (!depot_user_path.has_single_element()) + depot_user_path.strip_last_element(); + + Vfs::Absolute_path depot_type_path { rom_session_label_path }; + depot_type_path.strip_prefix(depot_user_path.string()); + while (!depot_type_path.has_single_element()) + depot_type_path.strip_last_element(); + if (depot_type_path != "/bin") + return; + + Vfs::Absolute_path depot_component_path { rom_session_label_path }; + depot_component_path.strip_prefix( + Directory::join(depot_user_path, depot_type_path).string()); + + Vfs::Absolute_path bin_installation_path { depot_user_path }; + bin_installation_path.append("/bin"); + bin_installation_path.append(depot_component_path.string()); + bin_installation_path.strip_last_element(); + + xml.node("archive", [&] () { + xml.attribute("path", &bin_installation_path.string()[1]); + xml.attribute("source", "no"); + }); + + Vfs::Absolute_path dbg_installation_path { depot_user_path }; + dbg_installation_path.append("/dbg"); + dbg_installation_path.append(depot_component_path.string()); + dbg_installation_path.strip_last_element(); + + xml.node("archive", [&] () { + xml.attribute("path", &dbg_installation_path.string()[1]); + xml.attribute("source", "no"); + }); + }); + }, [&] () { + Genode::error(" XML node not found"); + }); + }); + }); + }); + } + + + void _handle_runtime_config_update() + { + try { + File_content const runtime_config { + _heap, _root_dir, _runtime_config_path, + File_content::Limit(512*1024) + }; + + runtime_config.xml([&] (Xml_node const config) { + config.with_sub_node("monitor", [&] (Xml_node const &monitor) { + _process_monitor_config(config, monitor); + }, [&] () { + Genode::error(" XML node not found"); + }); + }); + } catch (File_content::Truncated_during_read) { + Genode::error("Could not read ", _runtime_config_path); + } + } + + + Main(Genode::Env &env) + : _env(env) + { + _base_archive = _build_info.xml().attribute_value("base", + Session_label::String()); + _handle_runtime_config_update(); + } +}; + + +void Component::construct(Genode::Env &env) +{ + static Main main(env); +} diff --git a/repos/gems/src/app/dbg_download/target.mk b/repos/gems/src/app/dbg_download/target.mk new file mode 100644 index 0000000000..119ad5d2d2 --- /dev/null +++ b/repos/gems/src/app/dbg_download/target.mk @@ -0,0 +1,3 @@ +TARGET = dbg_download +SRC_CC = main.cc +LIBS = base vfs