Blame tests/dwfl-report-segment-contiguous.c

Packit Service 35cfd5
/* Test bug in dwfl_report_segment() coalescing.
Packit Service 35cfd5
   Copyright (C) 2019 Facebook
Packit Service 35cfd5
   This file is part of elfutils.
Packit Service 35cfd5
Packit Service 35cfd5
   This file is free software; you can redistribute it and/or modify
Packit Service 35cfd5
   it under the terms of the GNU General Public License as published by
Packit Service 35cfd5
   the Free Software Foundation; either version 3 of the License, or
Packit Service 35cfd5
   (at your option) any later version.
Packit Service 35cfd5
Packit Service 35cfd5
   elfutils is distributed in the hope that it will be useful, but
Packit Service 35cfd5
   WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 35cfd5
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service 35cfd5
   GNU General Public License for more details.
Packit Service 35cfd5
Packit Service 35cfd5
   You should have received a copy of the GNU General Public License
Packit Service 35cfd5
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
Packit Service 35cfd5
Packit Service 35cfd5
#include <config.h>
Packit Service 35cfd5
#include <assert.h>
Packit Service 35cfd5
#include <inttypes.h>
Packit Service 35cfd5
#include <stdio.h>
Packit Service 35cfd5
#include <stdio_ext.h>
Packit Service 35cfd5
#include <locale.h>
Packit Service 35cfd5
#include ELFUTILS_HEADER(dwfl)
Packit Service 35cfd5
Packit Service 35cfd5
Packit Service 35cfd5
static const Dwfl_Callbacks offline_callbacks =
Packit Service 35cfd5
  {
Packit Service 35cfd5
    .find_debuginfo = INTUSE(dwfl_standard_find_debuginfo),
Packit Service 35cfd5
    .section_address = INTUSE(dwfl_offline_section_address),
Packit Service 35cfd5
  };
Packit Service 35cfd5
Packit Service 35cfd5
Packit Service 35cfd5
int
Packit Service 35cfd5
main (void)
Packit Service 35cfd5
{
Packit Service 35cfd5
  /* We use no threads here which can interfere with handling a stream.  */
Packit Service 35cfd5
  (void) __fsetlocking (stdout, FSETLOCKING_BYCALLER);
Packit Service 35cfd5
Packit Service 35cfd5
  /* Set locale.  */
Packit Service 35cfd5
  (void) setlocale (LC_ALL, "");
Packit Service 35cfd5
Packit Service 35cfd5
  Dwfl *dwfl = dwfl_begin (&offline_callbacks);
Packit Service 35cfd5
  assert (dwfl != NULL);
Packit Service 35cfd5
Packit Service 35cfd5
  GElf_Phdr phdr1 =
Packit Service 35cfd5
    {
Packit Service 35cfd5
      .p_type = PT_LOAD,
Packit Service 35cfd5
      .p_flags = PF_R,
Packit Service 35cfd5
      .p_offset = 0xf00,
Packit Service 35cfd5
      .p_vaddr = 0xf00,
Packit Service 35cfd5
      .p_filesz = 0x100,
Packit Service 35cfd5
      .p_memsz = 0x100,
Packit Service 35cfd5
      .p_align = 4,
Packit Service 35cfd5
    };
Packit Service 35cfd5
Packit Service 35cfd5
  int ndx = dwfl_report_segment (dwfl, 1, &phdr1, 0, dwfl);
Packit Service 35cfd5
  assert(ndx == 1);
Packit Service 35cfd5
Packit Service 35cfd5
  ndx = dwfl_addrsegment (dwfl, 0xf00, NULL);
Packit Service 35cfd5
  assert(ndx == 1);
Packit Service 35cfd5
Packit Service 35cfd5
  GElf_Phdr phdr2 =
Packit Service 35cfd5
    {
Packit Service 35cfd5
      .p_type = PT_LOAD,
Packit Service 35cfd5
      .p_flags = PF_R | PF_W,
Packit Service 35cfd5
      .p_offset = 0x1000,
Packit Service 35cfd5
      .p_vaddr = 0x1000,
Packit Service 35cfd5
      .p_filesz = 0x100,
Packit Service 35cfd5
      .p_memsz = 0x100,
Packit Service 35cfd5
      .p_align = 4,
Packit Service 35cfd5
    };
Packit Service 35cfd5
  ndx = dwfl_report_segment (dwfl, 2, &phdr2, 0, dwfl);
Packit Service 35cfd5
  assert(ndx == 2);
Packit Service 35cfd5
Packit Service 35cfd5
  ndx = dwfl_addrsegment (dwfl, 0x1000, NULL);
Packit Service 35cfd5
  assert(ndx == 1 || ndx == 2);
Packit Service 35cfd5
Packit Service 35cfd5
  dwfl_end (dwfl);
Packit Service 35cfd5
Packit Service 35cfd5
  return 0;
Packit Service 35cfd5
}