Files
third_party_elfutils/tests/line2addr.c
T
Mark Wielaard de2ed97f33 Update name, license and contributor policy.
* Change name from "Red Hat elfutils" to "elfutils".
* Update license of standalone tools and test from GPLv2 to GPLv3+.
* Change license of libraries from GPLv2+exception to GPLv2/LGPLv3+.
* Add Developer Certificate of Origin based contributor policy.

top-level:

- COPYING: Upgraded from GPLv2 to GPLv3.
- CONTRIBUTING, COPYING-GPLv2, COPYING-LGPLv3: New files.
- NEWS: Added note about new contribution and license policy.
- Makefile.am: Updated to GPLv3, added new files to EXTRA_DIST.
- configure.ac: Update to GPLv3, changed AC_INIT name to 'elfutils'.

backends, lib, libasm, libcpu, libdw, libdwfl, libebl, libelf:

- All files updated to GPLv2/LGPLv3+. Except some very small files
  (<5 lines) which didn't have any headers at all before, the linker
  .maps files and the libcpu/defs files which only contain data and
  libelf/elf.h which comes from glibc and is under LGPLv2+.

config:

- elfutils.spec.in: Add new License: headers and new %doc files.
- Update all license headers to GPLv2/LGPLv3+ for files used by libs.

src, tests:

- All files updated to GPLv3+. Except for the test bz2 data files, the
  linker maps and script files and some very small files (<5 lines)
  that don't have any headers.

Signed-off-by: Richard Fontana <rfontana@redhat.com>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
2012-06-05 23:12:05 +02:00

149 lines
3.5 KiB
C

/* Copyright (C) 2005 Red Hat, Inc.
This file is part of elfutils.
This file 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.
elfutils 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/>. */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <inttypes.h>
#include <assert.h>
#include ELFUTILS_HEADER(dwfl)
#include <argp.h>
#include <stdio.h>
#include <locale.h>
#include <stdlib.h>
#include <string.h>
#include <error.h>
static void
print_address (Dwfl_Module *mod, Dwarf_Addr address)
{
int n = dwfl_module_relocations (mod);
if (n < 0)
error (0, 0, "dwfl_module_relocations: %s", dwfl_errmsg (-1));
else if (n > 0)
{
int i = dwfl_module_relocate_address (mod, &address);
if (i < 0)
error (0, 0, "dwfl_module_relocate_address: %s", dwfl_errmsg (-1));
else
{
const char *modname = dwfl_module_info (mod, NULL, NULL, NULL,
NULL, NULL, NULL, NULL);
const char *secname = dwfl_module_relocation_info (mod, i, NULL);
if (n > 1 || secname[0] != '\0')
printf ("%s(%s)+%#" PRIx64, modname, secname, address);
else
printf ("%s+%#" PRIx64, modname, address);
return;
}
}
printf ("%#" PRIx64, address);
}
struct args
{
const char *arg;
char *file;
int line;
};
static int
handle_module (Dwfl_Module *mod __attribute__ ((unused)),
void **udata __attribute__ ((unused)),
const char *modname, Dwarf_Addr base __attribute__ ((unused)),
Dwarf *dbg __attribute__ ((unused)),
Dwarf_Addr bias __attribute__ ((unused)), void *arg)
{
const struct args *const a = arg;
Dwfl_Line **lines = NULL;
size_t nlines = 0;
if (dwfl_module_getsrc_file (mod, a->file, a->line, 0, &lines, &nlines) == 0)
{
for (size_t inner = 0; inner < nlines; ++inner)
{
Dwarf_Addr addr;
int line = a->line, col = 0;
const char *file = dwfl_lineinfo (lines[inner], &addr, &line, &col,
NULL, NULL);
if (file != NULL)
{
printf ("%s -> ", a->arg);
print_address (mod, addr);
if (modname[0] != '\0')
printf (" (%s:", modname);
if (strcmp (file, a->file) || line != a->line || col != 0)
printf (" %s%s:%d", modname[0] != '\0' ? "" : "(",
file, line);
if (col != 0)
printf (":%d", col);
if (modname[0] != '\0'
|| strcmp (file, a->file) || line != a->line || col != 0)
puts (")");
else
puts ("");
}
}
free (lines);
}
return DWARF_CB_OK;
}
int
main (int argc, char *argv[])
{
int cnt;
/* Set locale. */
(void) setlocale (LC_ALL, "");
Dwfl *dwfl = NULL;
(void) argp_parse (dwfl_standard_argp (), argc, argv, 0, &cnt, &dwfl);
assert (dwfl != NULL);
for (; cnt < argc; ++cnt)
{
struct args a = { .arg = argv[cnt] };
switch (sscanf (a.arg, "%m[^:]:%d", &a.file, &a.line))
{
default:
case 0:
printf ("ignored %s\n", argv[cnt]);
continue;
case 1:
a.line = 0;
break;
case 2:
break;
}
(void) dwfl_getdwarf (dwfl, &handle_module, &a, 0);
free (a.file);
}
dwfl_end (dwfl);
return 0;
}