1 /* Copyright (C) 2005 Red Hat, Inc.
2 This file is part of elfutils.
4 This file is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 elfutils is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 #include ELFUTILS_HEADER(dwfl)
33 print_address (Dwfl_Module *mod, Dwarf_Addr address)
35 int n = dwfl_module_relocations (mod);
37 error (0, 0, "dwfl_module_relocations: %s", dwfl_errmsg (-1));
40 int i = dwfl_module_relocate_address (mod, &address);
42 error (0, 0, "dwfl_module_relocate_address: %s", dwfl_errmsg (-1));
45 const char *modname = dwfl_module_info (mod, NULL, NULL, NULL,
46 NULL, NULL, NULL, NULL);
47 const char *secname = dwfl_module_relocation_info (mod, i, NULL);
48 if (n > 1 || secname[0] != '\0')
49 printf ("%s(%s)+%#" PRIx64, modname, secname, address);
51 printf ("%s+%#" PRIx64, modname, address);
56 printf ("%#" PRIx64, address);
68 handle_module (Dwfl_Module *mod __attribute__ ((unused)),
69 void **udata __attribute__ ((unused)),
70 const char *modname, Dwarf_Addr base __attribute__ ((unused)),
71 Dwarf *dbg __attribute__ ((unused)),
72 Dwarf_Addr bias __attribute__ ((unused)), void *arg)
74 const struct args *const a = arg;
76 Dwfl_Line **lines = NULL;
79 if (dwfl_module_getsrc_file (mod, a->file, a->line, 0, &lines, &nlines) == 0)
81 for (size_t inner = 0; inner < nlines; ++inner)
84 int line = a->line, col = 0;
85 const char *file = dwfl_lineinfo (lines[inner], &addr, &line, &col,
89 printf ("%s -> ", a->arg);
90 print_address (mod, addr);
91 if (modname[0] != '\0')
92 printf (" (%s:", modname);
93 if (strcmp (file, a->file) || line != a->line || col != 0)
94 printf (" %s%s:%d", modname[0] != '\0' ? "" : "(",
98 if (modname[0] != '\0'
99 || strcmp (file, a->file) || line != a->line || col != 0)
112 main (int argc, char *argv[])
117 (void) setlocale (LC_ALL, "");
120 (void) argp_parse (dwfl_standard_argp (), argc, argv, 0, &cnt, &dwfl);
121 assert (dwfl != NULL);
123 for (; cnt < argc; ++cnt)
125 struct args a = { .arg = argv[cnt] };
127 switch (sscanf (a.arg, "%m[^:]:%d", &a.file, &a.line))
131 printf ("ignored %s\n", argv[cnt]);
140 (void) dwfl_getdwarf (dwfl, &handle_module, &a, 0);