[sysprof/wip/chergert/path-resolver] tests: add util to extract build-id



commit 5f43a57ab0575a9d28ead8d1bb6062a148648fed
Author: Christian Hergert <chergert redhat com>
Date:   Thu Sep 16 22:59:22 2021 -0700

    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(+)
---
diff --git a/src/tests/meson.build b/src/tests/meson.build
index 603ce98..85c325a 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 0000000..804392c
--- /dev/null
+++ b/src/tests/read-build-id.c
@@ -0,0 +1,52 @@
+/* read-build-id.c
+ *
+ * Copyright 2021 Christian Hergert <chergert redhat com>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ * 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;
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]