1/* Test program for dwfl_report_elf incorrect BASE alignment.
2   Copyright (C) 2013 Red Hat, Inc.
3   This file is part of elfutils.
4
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.
9
10   elfutils is distributed in the hope that it will be useful, but
11   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#include <config.h>
19#include <assert.h>
20#include <inttypes.h>
21#include <stdio.h>
22#include <stdio_ext.h>
23#include <error.h>
24#include <locale.h>
25#include <string.h>
26#include <stdlib.h>
27#include ELFUTILS_HEADER(dwfl)
28
29
30static const Dwfl_Callbacks offline_callbacks =
31  {
32    .find_debuginfo = INTUSE(dwfl_standard_find_debuginfo),
33    .section_address = INTUSE(dwfl_offline_section_address),
34  };
35
36
37int
38main (int argc, char **argv)
39{
40  /* We use no threads here which can interfere with handling a stream.  */
41  (void) __fsetlocking (stdout, FSETLOCKING_BYCALLER);
42
43  /* Set locale.  */
44  (void) setlocale (LC_ALL, "");
45
46  if (argc != 5)
47    error (1, 0, "dwfl-report-elf-align shlib.so base funcaddr funcname");
48
49  Dwfl *dwfl = dwfl_begin (&offline_callbacks);
50  assert (dwfl != NULL);
51
52  char *endptr;
53  uintptr_t base = strtoull (argv[2], &endptr, 0);
54  assert (endptr && !*endptr);
55
56  Dwfl_Module *mod = dwfl_report_elf (dwfl, argv[1], argv[1], -1, base, false);
57  assert (mod != NULL);
58
59  uintptr_t funcaddr = strtoull (argv[3], &endptr, 0);
60  assert (endptr && !*endptr);
61
62  Dwfl_Module *mod_found = dwfl_addrmodule (dwfl, funcaddr);
63  assert (mod_found == mod);
64
65  const char *symname = dwfl_module_addrname (mod, funcaddr);
66  assert (symname != NULL);
67  assert (strcmp (symname, argv[4]) == 0);
68
69  dwfl_end (dwfl);
70
71  return 0;
72}
73