Imported Upstream version 0.153
[platform/upstream/elfutils.git] / tests / dwfl-bug-addr-overflow.c
1 /* Test program for libdwfl basic module tracking, relocation.
2    Copyright (C) 2007 Red Hat, Inc.
3    This file is part of Red Hat elfutils.
4
5    Red Hat elfutils is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by the
7    Free Software Foundation; version 2 of the License.
8
9    Red Hat 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 GNU
12    General Public License for more details.
13
14    You should have received a copy of the GNU General Public License along
15    with Red Hat elfutils; if not, write to the Free Software Foundation,
16    Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
17
18    Red Hat elfutils is an included package of the Open Invention Network.
19    An included package of the Open Invention Network is a package for which
20    Open Invention Network licensees cross-license their patents.  No patent
21    license is granted, either expressly or impliedly, by designation as an
22    included package.  Should you wish to participate in the Open Invention
23    Network licensing program, please visit www.openinventionnetwork.com
24    <http://www.openinventionnetwork.com>.  */
25
26 #include <config.h>
27 #include <assert.h>
28 #include <inttypes.h>
29 #include <stdio.h>
30 #include <stdio_ext.h>
31 #include <error.h>
32 #include <locale.h>
33 #include ELFUTILS_HEADER(dwfl)
34
35
36 static const Dwfl_Callbacks offline_callbacks =
37   {
38     .find_debuginfo = INTUSE(dwfl_standard_find_debuginfo),
39     .section_address = INTUSE(dwfl_offline_section_address),
40   };
41
42
43 int
44 main (void)
45 {
46   /* We use no threads here which can interfere with handling a stream.  */
47   (void) __fsetlocking (stdout, FSETLOCKING_BYCALLER);
48
49   /* Set locale.  */
50   (void) setlocale (LC_ALL, "");
51
52   Dwfl *dwfl = dwfl_begin (&offline_callbacks);
53   assert (dwfl != NULL);
54
55   Dwfl_Module *high = dwfl_report_module (dwfl, "high",
56                                           UINT64_C (0xffffffff00010000),
57                                           UINT64_C (0xffffffff00020000));
58   assert (high);
59   Dwfl_Module *low = dwfl_report_module (dwfl, "low",
60                                          UINT64_C (0x00010000),
61                                          UINT64_C (0x00020000));
62   assert (low);
63   Dwfl_Module *middle = dwfl_report_module (dwfl, "middle",
64                                             UINT64_C (0xffff00010000),
65                                             UINT64_C (0xffff00020000));
66   assert (middle);
67
68   int ret = dwfl_report_end (dwfl, NULL, NULL);
69   assert (ret == 0);
70
71   Dwfl_Module *mod = dwfl_addrmodule (dwfl, UINT64_C (0xffffffff00010123));
72   assert (mod == high);
73   mod = dwfl_addrmodule (dwfl, UINT64_C (0x00010123));
74   assert (mod == low);
75   mod = dwfl_addrmodule (dwfl, UINT64_C (0xffff00010123));
76   assert (mod == middle);
77
78   dwfl_end (dwfl);
79
80   return 0;
81 }