Roland McGrath | 43da989 | 2007-04-16 23:13:37 +0000 | [diff] [blame] | 1 | /* Test program for libdwfl ... foo |
| 2 | Copyright (C) 2007 Red Hat, Inc. |
Mark Wielaard | de2ed97 | 2012-06-05 17:15:16 +0200 | [diff] [blame] | 3 | This file is part of elfutils. |
Roland McGrath | 43da989 | 2007-04-16 23:13:37 +0000 | [diff] [blame] | 4 | |
Mark Wielaard | de2ed97 | 2012-06-05 17:15:16 +0200 | [diff] [blame] | 5 | 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 McGrath | 43da989 | 2007-04-16 23:13:37 +0000 | [diff] [blame] | 9 | |
Mark Wielaard | de2ed97 | 2012-06-05 17:15:16 +0200 | [diff] [blame] | 10 | elfutils is distributed in the hope that it will be useful, but |
Roland McGrath | 43da989 | 2007-04-16 23:13:37 +0000 | [diff] [blame] | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
Mark Wielaard | de2ed97 | 2012-06-05 17:15:16 +0200 | [diff] [blame] | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | GNU General Public License for more details. |
Roland McGrath | 43da989 | 2007-04-16 23:13:37 +0000 | [diff] [blame] | 14 | |
Mark Wielaard | de2ed97 | 2012-06-05 17:15:16 +0200 | [diff] [blame] | 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/>. */ |
Roland McGrath | 43da989 | 2007-04-16 23:13:37 +0000 | [diff] [blame] | 17 | |
| 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 McGrath | e4c22ea | 2007-10-23 13:07:39 +0000 | [diff] [blame] | 32 | static int |
Roland McGrath | 43da989 | 2007-04-16 23:13:37 +0000 | [diff] [blame] | 33 | handle_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 McGrath | e4c22ea | 2007-10-23 13:07:39 +0000 | [diff] [blame] | 40 | { |
| 41 | error (0, 0, "%#" PRIx64 ": dwfl_module_address_section: %s", |
| 42 | address, dwfl_errmsg (-1)); |
| 43 | return 1; |
| 44 | } |
Roland McGrath | 43da989 | 2007-04-16 23:13:37 +0000 | [diff] [blame] | 45 | 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 McGrath | e4c22ea | 2007-10-23 13:07:39 +0000 | [diff] [blame] | 49 | return 0; |
Roland McGrath | 43da989 | 2007-04-16 23:13:37 +0000 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | int |
| 53 | main (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 McGrath | e4c22ea | 2007-10-23 13:07:39 +0000 | [diff] [blame] | 72 | result |= handle_address (dwfl, addr); |
Roland McGrath | 43da989 | 2007-04-16 23:13:37 +0000 | [diff] [blame] | 73 | else |
| 74 | result = 1; |
| 75 | } |
| 76 | |
| 77 | dwfl_end (dwfl); |
| 78 | |
| 79 | return result; |
| 80 | } |