blob: 21e470a3a23185328d30c445283bfd974eeb1750 [file] [log] [blame]
Roland McGrath43da9892007-04-16 23:13:37 +00001/* Test program for libdwfl ... foo
2 Copyright (C) 2007 Red Hat, Inc.
Mark Wielaardde2ed972012-06-05 17:15:16 +02003 This file is part of elfutils.
Roland McGrath43da9892007-04-16 23:13:37 +00004
Mark Wielaardde2ed972012-06-05 17:15:16 +02005 This file 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.
Roland McGrath43da9892007-04-16 23:13:37 +00009
Mark Wielaardde2ed972012-06-05 17:15:16 +020010 elfutils is distributed in the hope that it will be useful, but
Roland McGrath43da9892007-04-16 23:13:37 +000011 WITHOUT ANY WARRANTY; without even the implied warranty of
Mark Wielaardde2ed972012-06-05 17:15:16 +020012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
Roland McGrath43da9892007-04-16 23:13:37 +000014
Mark Wielaardde2ed972012-06-05 17:15:16 +020015 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/>. */
Roland McGrath43da9892007-04-16 23:13:37 +000017
18#include <config.h>
19#include <assert.h>
20#include <inttypes.h>
21#include <sys/types.h>
22#include <stdio.h>
23#include <stdio_ext.h>
24#include <stdlib.h>
25#include <string.h>
26#include <error.h>
27#include <locale.h>
28#include <argp.h>
29#include ELFUTILS_HEADER(dwfl)
30#include <dwarf.h>
31
Roland McGrathe4c22ea2007-10-23 13:07:39 +000032static int
Roland McGrath43da9892007-04-16 23:13:37 +000033handle_address (Dwfl *dwfl, Dwarf_Addr address)
34{
35 Dwfl_Module *mod = dwfl_addrmodule (dwfl, address);
36 Dwarf_Addr adjusted = address;
37 Dwarf_Addr bias;
38 Elf_Scn *scn = dwfl_module_address_section (mod, &adjusted, &bias);
39 if (scn == NULL)
Roland McGrathe4c22ea2007-10-23 13:07:39 +000040 {
41 error (0, 0, "%#" PRIx64 ": dwfl_module_address_section: %s",
42 address, dwfl_errmsg (-1));
43 return 1;
44 }
Roland McGrath43da9892007-04-16 23:13:37 +000045 printf ("address %#" PRIx64 " => module \"%s\" section %zu + %#" PRIx64 "\n",
46 address,
47 dwfl_module_info (mod, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
48 elf_ndxscn (scn), adjusted);
Roland McGrathe4c22ea2007-10-23 13:07:39 +000049 return 0;
Roland McGrath43da9892007-04-16 23:13:37 +000050}
51
52int
53main (int argc, char **argv)
54{
55 /* We use no threads here which can interfere with handling a stream. */
56 (void) __fsetlocking (stdout, FSETLOCKING_BYCALLER);
57
58 /* Set locale. */
59 (void) setlocale (LC_ALL, "");
60
61 int remaining;
62 Dwfl *dwfl = NULL;
63 (void) argp_parse (dwfl_standard_argp (), argc, argv, 0, &remaining, &dwfl);
64 assert (dwfl != NULL);
65
66 int result = 0;
67 for (; remaining < argc; ++remaining)
68 {
69 char *endp;
70 uintmax_t addr = strtoumax (argv[remaining], &endp, 0);
71 if (endp != argv[remaining])
Roland McGrathe4c22ea2007-10-23 13:07:39 +000072 result |= handle_address (dwfl, addr);
Roland McGrath43da9892007-04-16 23:13:37 +000073 else
74 result = 1;
75 }
76
77 dwfl_end (dwfl);
78
79 return result;
80}