103333823c75a1c1887e923828113a1b0fd12020cElliott Hughes/* Test program for libdwfl basic module tracking, relocation.
203333823c75a1c1887e923828113a1b0fd12020cElliott Hughes   Copyright (C) 2007 Red Hat, Inc.
303333823c75a1c1887e923828113a1b0fd12020cElliott Hughes   This file is part of elfutils.
403333823c75a1c1887e923828113a1b0fd12020cElliott Hughes
503333823c75a1c1887e923828113a1b0fd12020cElliott Hughes   This file is free software; you can redistribute it and/or modify
603333823c75a1c1887e923828113a1b0fd12020cElliott Hughes   it under the terms of the GNU General Public License as published by
703333823c75a1c1887e923828113a1b0fd12020cElliott Hughes   the Free Software Foundation; either version 3 of the License, or
803333823c75a1c1887e923828113a1b0fd12020cElliott Hughes   (at your option) any later version.
903333823c75a1c1887e923828113a1b0fd12020cElliott Hughes
1003333823c75a1c1887e923828113a1b0fd12020cElliott Hughes   elfutils is distributed in the hope that it will be useful, but
1103333823c75a1c1887e923828113a1b0fd12020cElliott Hughes   WITHOUT ANY WARRANTY; without even the implied warranty of
1203333823c75a1c1887e923828113a1b0fd12020cElliott Hughes   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1303333823c75a1c1887e923828113a1b0fd12020cElliott Hughes   GNU General Public License for more details.
1403333823c75a1c1887e923828113a1b0fd12020cElliott Hughes
1503333823c75a1c1887e923828113a1b0fd12020cElliott Hughes   You should have received a copy of the GNU General Public License
1603333823c75a1c1887e923828113a1b0fd12020cElliott Hughes   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
1703333823c75a1c1887e923828113a1b0fd12020cElliott Hughes
1803333823c75a1c1887e923828113a1b0fd12020cElliott Hughes#include <config.h>
1903333823c75a1c1887e923828113a1b0fd12020cElliott Hughes#include <assert.h>
2003333823c75a1c1887e923828113a1b0fd12020cElliott Hughes#include <inttypes.h>
2103333823c75a1c1887e923828113a1b0fd12020cElliott Hughes#include <stdio.h>
2203333823c75a1c1887e923828113a1b0fd12020cElliott Hughes#include <stdio_ext.h>
2303333823c75a1c1887e923828113a1b0fd12020cElliott Hughes#include <error.h>
2403333823c75a1c1887e923828113a1b0fd12020cElliott Hughes#include <locale.h>
2503333823c75a1c1887e923828113a1b0fd12020cElliott Hughes#include ELFUTILS_HEADER(dwfl)
2603333823c75a1c1887e923828113a1b0fd12020cElliott Hughes
2703333823c75a1c1887e923828113a1b0fd12020cElliott Hughes
2803333823c75a1c1887e923828113a1b0fd12020cElliott Hughesstatic const Dwfl_Callbacks offline_callbacks =
2903333823c75a1c1887e923828113a1b0fd12020cElliott Hughes  {
3003333823c75a1c1887e923828113a1b0fd12020cElliott Hughes    .find_debuginfo = INTUSE(dwfl_standard_find_debuginfo),
3103333823c75a1c1887e923828113a1b0fd12020cElliott Hughes    .section_address = INTUSE(dwfl_offline_section_address),
3203333823c75a1c1887e923828113a1b0fd12020cElliott Hughes  };
3303333823c75a1c1887e923828113a1b0fd12020cElliott Hughes
3403333823c75a1c1887e923828113a1b0fd12020cElliott Hughes
3503333823c75a1c1887e923828113a1b0fd12020cElliott Hughesint
3603333823c75a1c1887e923828113a1b0fd12020cElliott Hughesmain (void)
3703333823c75a1c1887e923828113a1b0fd12020cElliott Hughes{
3803333823c75a1c1887e923828113a1b0fd12020cElliott Hughes  /* We use no threads here which can interfere with handling a stream.  */
3903333823c75a1c1887e923828113a1b0fd12020cElliott Hughes  (void) __fsetlocking (stdout, FSETLOCKING_BYCALLER);
4003333823c75a1c1887e923828113a1b0fd12020cElliott Hughes
4103333823c75a1c1887e923828113a1b0fd12020cElliott Hughes  /* Set locale.  */
4203333823c75a1c1887e923828113a1b0fd12020cElliott Hughes  (void) setlocale (LC_ALL, "");
4303333823c75a1c1887e923828113a1b0fd12020cElliott Hughes
4403333823c75a1c1887e923828113a1b0fd12020cElliott Hughes  Dwfl *dwfl = dwfl_begin (&offline_callbacks);
4503333823c75a1c1887e923828113a1b0fd12020cElliott Hughes  assert (dwfl != NULL);
4603333823c75a1c1887e923828113a1b0fd12020cElliott Hughes
4703333823c75a1c1887e923828113a1b0fd12020cElliott Hughes  Dwfl_Module *high = dwfl_report_module (dwfl, "high",
4803333823c75a1c1887e923828113a1b0fd12020cElliott Hughes					  UINT64_C (0xffffffff00010000),
4903333823c75a1c1887e923828113a1b0fd12020cElliott Hughes					  UINT64_C (0xffffffff00020000));
5003333823c75a1c1887e923828113a1b0fd12020cElliott Hughes  assert (high);
5103333823c75a1c1887e923828113a1b0fd12020cElliott Hughes  Dwfl_Module *low = dwfl_report_module (dwfl, "low",
5203333823c75a1c1887e923828113a1b0fd12020cElliott Hughes					 UINT64_C (0x00010000),
5303333823c75a1c1887e923828113a1b0fd12020cElliott Hughes					 UINT64_C (0x00020000));
5403333823c75a1c1887e923828113a1b0fd12020cElliott Hughes  assert (low);
5503333823c75a1c1887e923828113a1b0fd12020cElliott Hughes  Dwfl_Module *middle = dwfl_report_module (dwfl, "middle",
5603333823c75a1c1887e923828113a1b0fd12020cElliott Hughes					    UINT64_C (0xffff00010000),
5703333823c75a1c1887e923828113a1b0fd12020cElliott Hughes					    UINT64_C (0xffff00020000));
5803333823c75a1c1887e923828113a1b0fd12020cElliott Hughes  assert (middle);
5903333823c75a1c1887e923828113a1b0fd12020cElliott Hughes
6003333823c75a1c1887e923828113a1b0fd12020cElliott Hughes  int ret = dwfl_report_end (dwfl, NULL, NULL);
6103333823c75a1c1887e923828113a1b0fd12020cElliott Hughes  assert (ret == 0);
6203333823c75a1c1887e923828113a1b0fd12020cElliott Hughes
6303333823c75a1c1887e923828113a1b0fd12020cElliott Hughes  Dwfl_Module *mod = dwfl_addrmodule (dwfl, UINT64_C (0xffffffff00010123));
6403333823c75a1c1887e923828113a1b0fd12020cElliott Hughes  assert (mod == high);
6503333823c75a1c1887e923828113a1b0fd12020cElliott Hughes  mod = dwfl_addrmodule (dwfl, UINT64_C (0x00010123));
6603333823c75a1c1887e923828113a1b0fd12020cElliott Hughes  assert (mod == low);
6703333823c75a1c1887e923828113a1b0fd12020cElliott Hughes  mod = dwfl_addrmodule (dwfl, UINT64_C (0xffff00010123));
6803333823c75a1c1887e923828113a1b0fd12020cElliott Hughes  assert (mod == middle);
6903333823c75a1c1887e923828113a1b0fd12020cElliott Hughes
7003333823c75a1c1887e923828113a1b0fd12020cElliott Hughes  dwfl_end (dwfl);
7103333823c75a1c1887e923828113a1b0fd12020cElliott Hughes
7203333823c75a1c1887e923828113a1b0fd12020cElliott Hughes  return 0;
7303333823c75a1c1887e923828113a1b0fd12020cElliott Hughes}
74