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