From 5f43a57ab0575a9d28ead8d1bb6062a148648fed Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Thu, 16 Sep 2021 22:59:22 -0700 Subject: [PATCH] tests: add util to extract build-id Easier to remember than readelf stuff and tests the same code paths. --- src/tests/meson.build | 5 ++++ src/tests/read-build-id.c | 52 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 src/tests/read-build-id.c diff --git a/src/tests/meson.build b/src/tests/meson.build index 603ce986..85c325a8 100644 --- a/src/tests/meson.build +++ b/src/tests/meson.build @@ -95,6 +95,11 @@ memory_stack_stash = executable('memory-stack-stash', 'memory-stack-stash.c', dependencies: test_deps, ) +read_build_id = executable('read-build-id', 'read-build-id.c', + c_args: test_cflags, + dependencies: test_deps, +) + show_page_usage = executable('show-page-usage', 'show-page-usage.c', c_args: test_cflags, dependencies: test_deps + [dependency('cairo')], diff --git a/src/tests/read-build-id.c b/src/tests/read-build-id.c new file mode 100644 index 00000000..804392c3 --- /dev/null +++ b/src/tests/read-build-id.c @@ -0,0 +1,52 @@ +/* read-build-id.c + * + * Copyright 2021 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 + */ + +#include "config.h" + +#include "elfparser.h" + +int +main (int argc, + char *argv[]) +{ + for (guint i = 1; i < argc; i++) + { + g_autoptr(GError) error = NULL; + const char *filename = argv[i]; + ElfParser *parser = elf_parser_new (filename, &error); + const char *build_id; + + if (parser == NULL) + { + if (error != NULL) + g_printerr ("%s: %s\n", filename, error->message); + else + g_printerr ("%s: Failed to load as ELF\n", filename); + g_clear_error (&error); + continue; + } + + build_id = elf_parser_get_build_id (parser); + g_print ("%s: %s\n", filename, build_id); + elf_parser_free (parser); + } + + return 0; +}