From 9a3a95a5caff2d558bba9262cf7405dca9602f29 Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Fri, 24 Jan 2020 10:54:32 -0800 Subject: [PATCH] podman: add debug directories from podman containers This is meant to allow us to find the debug files for a given library for podman containers running as the current user. However, we still need to try to translate the fuse-overlayfs paths when parsing the /proc/pid/mounts or we'll have incorrect paths coming from the event stream. --- src/libsysprof/meson.build | 1 + src/libsysprof/sysprof-elf-symbol-resolver.c | 9 +++ src/libsysprof/sysprof-podman.c | 65 ++++++++++++++++++++ src/libsysprof/sysprof-podman.h | 29 +++++++++ 4 files changed, 104 insertions(+) create mode 100644 src/libsysprof/sysprof-podman.c create mode 100644 src/libsysprof/sysprof-podman.h diff --git a/src/libsysprof/meson.build b/src/libsysprof/meson.build index 77c76c70..2b407441 100644 --- a/src/libsysprof/meson.build +++ b/src/libsysprof/meson.build @@ -69,6 +69,7 @@ libsysprof_private_sources = [ 'sysprof-line-reader.c', 'sysprof-map-lookaside.c', 'sysprof-mountinfo.c', + 'sysprof-podman.c', 'sysprof-polkit.c', 'sysprof-symbol-map.c', ipc_service_src, diff --git a/src/libsysprof/sysprof-elf-symbol-resolver.c b/src/libsysprof/sysprof-elf-symbol-resolver.c index 10b97165..5dec9ecb 100644 --- a/src/libsysprof/sysprof-elf-symbol-resolver.c +++ b/src/libsysprof/sysprof-elf-symbol-resolver.c @@ -27,6 +27,7 @@ #include "sysprof-elf-symbol-resolver.h" #include "sysprof-flatpak.h" #include "sysprof-map-lookaside.h" +#include "sysprof-podman.h" struct _SysprofElfSymbolResolver { @@ -92,12 +93,20 @@ free_element_string (gpointer data) static void sysprof_elf_symbol_resolver_init (SysprofElfSymbolResolver *self) { + g_auto(GStrv) podman_dirs = NULL; + self->debug_dirs = g_array_new (TRUE, FALSE, sizeof (gchar *)); g_array_set_clear_func (self->debug_dirs, free_element_string); + sysprof_elf_symbol_resolver_add_debug_dir (self, "/usr/lib/debug"); sysprof_elf_symbol_resolver_add_debug_dir (self, "/usr/lib32/debug"); sysprof_elf_symbol_resolver_add_debug_dir (self, "/usr/lib64/debug"); + /* The user may have podman/toolbox containers */ + podman_dirs = sysprof_podman_debug_dirs (); + for (guint i = 0; podman_dirs[i]; i++) + sysprof_elf_symbol_resolver_add_debug_dir (self, podman_dirs[i]); + if (is_flatpak ()) { g_auto(GStrv) debug_dirs = sysprof_flatpak_debug_dirs (); diff --git a/src/libsysprof/sysprof-podman.c b/src/libsysprof/sysprof-podman.c new file mode 100644 index 00000000..3d2a51b3 --- /dev/null +++ b/src/libsysprof/sysprof-podman.c @@ -0,0 +1,65 @@ +/* sysprof-podman.c + * + * Copyright 2019 Christian Hergert + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#define G_LOG_DOMAIN "sysprof-podman" + +#include "config.h" + +#include "sysprof-podman.h" + +void +_sysprof_podman_debug_dirs (GPtrArray *dirs) +{ + g_autofree gchar *base_path = NULL; + g_autoptr(GDir) dir = NULL; + const gchar *name; + + g_assert (dirs != NULL); + + base_path = g_build_filename (g_get_user_data_dir (), + "containres", + "storage", + "overlay", + NULL); + + if (!(dir = g_dir_open (base_path, 0, NULL))) + return; + + while ((name = g_dir_read_name (dir))) + { + g_autofree gchar *debug_path = NULL; + + debug_path = g_build_filename (base_path, name, "diff", + "usr", "lib", "debug", + NULL); + + if (g_file_test (debug_path, G_FILE_TEST_IS_DIR)) + g_ptr_array_add (dirs, g_steal_pointer (&debug_path)); + } +} + +gchar ** +sysprof_podman_debug_dirs (void) +{ + GPtrArray *dirs = g_ptr_array_new (); + _sysprof_podman_debug_dirs (dirs); + g_ptr_array_add (dirs, NULL); + return (gchar **)g_ptr_array_free (dirs, FALSE); +} diff --git a/src/libsysprof/sysprof-podman.h b/src/libsysprof/sysprof-podman.h new file mode 100644 index 00000000..b113f6f4 --- /dev/null +++ b/src/libsysprof/sysprof-podman.h @@ -0,0 +1,29 @@ +/* sysprof-podman.h + * + * Copyright 2020 Christian Hergert + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#pragma once + +#include + +G_BEGIN_DECLS + +gchar **sysprof_podman_debug_dirs (void); + +G_END_DECLS