1/* Test program for libdwfl basic module tracking, relocation.
2   Copyright (C) 2007 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 <locale.h>
24#include ELFUTILS_HEADER(dwfl)
25
26
27static const Dwfl_Callbacks offline_callbacks =
28  {
29    .find_debuginfo = INTUSE(dwfl_standard_find_debuginfo),
30    .section_address = INTUSE(dwfl_offline_section_address),
31  };
32
33
34int
35main (void)
36{
37  /* We use no threads here which can interfere with handling a stream.  */
38  (void) __fsetlocking (stdout, FSETLOCKING_BYCALLER);
39
40  /* Set locale.  */
41  (void) setlocale (LC_ALL, "");
42
43  Dwfl *dwfl = dwfl_begin (&offline_callbacks);
44  assert (dwfl != NULL);
45
46  Dwfl_Module *high = dwfl_report_module (dwfl, "high",
47					  UINT64_C (0xffffffff00010000),
48					  UINT64_C (0xffffffff00020000));
49  assert (high);
50  Dwfl_Module *low = dwfl_report_module (dwfl, "low",
51					 UINT64_C (0x00010000),
52					 UINT64_C (0x00020000));
53  assert (low);
54  Dwfl_Module *middle = dwfl_report_module (dwfl, "middle",
55					    UINT64_C (0xffff00010000),
56					    UINT64_C (0xffff00020000));
57  assert (middle);
58
59  int ret = dwfl_report_end (dwfl, NULL, NULL);
60  assert (ret == 0);
61
62  Dwfl_Module *mod = dwfl_addrmodule (dwfl, UINT64_C (0xffffffff00010123));
63  assert (mod == high);
64  mod = dwfl_addrmodule (dwfl, UINT64_C (0x00010123));
65  assert (mod == low);
66  mod = dwfl_addrmodule (dwfl, UINT64_C (0xffff00010123));
67  assert (mod == middle);
68
69  dwfl_end (dwfl);
70
71  return 0;
72}
73