Debian Codegraph @

src/libsysprof/tests/read-build-id.c

raw
1 /* read-build-id.c
2 *
3 * Copyright 2021 Christian Hergert <[email protected]>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * SPDX-License-Identifier: GPL-3.0-or-later
19 */
20
21 #include "config.h"
22
23 #include "elfparser.h"
24
25 int
26 main (int argc,
27 char *argv[])
28 {
29 for (guint i = 1; i < argc; i++)
30 {
31 g_autoptr(GError) error = NULL;
32 const char *filename = argv[i];
33 ElfParser *parser = elf_parser_new (filename, &error);
34 const char *build_id;
35 const char *debug_link;
36 guint crc;
37
38 if (parser == NULL)
39 {
40 if (error != NULL)
41 g_printerr ("%s: %s\n", filename, error->message);
42 else
43 g_printerr ("%s: Failed to load as ELF\n", filename);
44 g_clear_error (&error);
45 continue;
46 }
47
48 build_id = elf_parser_get_build_id (parser);
49 debug_link = elf_parser_get_debug_link (parser, &crc);
50
51 g_print ("%s: %s (%s)\n", filename, build_id, debug_link);
52
53 elf_parser_free (parser);
54 }
55
56 return 0;
57 }