Blame tests/dwfl-bug-getmodules.c

Packit 032894
/* Test program for dwfl_getmodules bug.
Packit 032894
   Copyright (C) 2008 Red Hat, Inc.
Packit 032894
   This file is part of elfutils.
Packit 032894
Packit 032894
   This file is free software; you can redistribute it and/or modify
Packit 032894
   it under the terms of the GNU General Public License as published by
Packit 032894
   the Free Software Foundation; either version 3 of the License, or
Packit 032894
   (at your option) any later version.
Packit 032894
Packit 032894
   elfutils is distributed in the hope that it will be useful, but
Packit 032894
   WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 032894
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 032894
   GNU General Public License for more details.
Packit 032894
Packit 032894
   You should have received a copy of the GNU General Public License
Packit 032894
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
Packit 032894
Packit 032894
#include <config.h>
Packit 032894
#include ELFUTILS_HEADER(dwfl)
Packit 032894
#include "system.h"
Packit 032894
Packit 032894
Packit 032894
static const Dwfl_Callbacks callbacks =
Packit 032894
  {
Packit 032894
    .find_elf = dwfl_linux_proc_find_elf,
Packit 032894
    .find_debuginfo = dwfl_standard_find_debuginfo,
Packit 032894
  };
Packit 032894
Packit 032894
static int
Packit 032894
iterate (Dwfl_Module *mod __attribute__ ((unused)),
Packit 032894
	 void **userdata __attribute__ ((unused)),
Packit 032894
	 const char *name __attribute__ ((unused)),
Packit 032894
	 Dwarf_Addr base, void *arg)
Packit 032894
{
Packit 032894
  if (base != 0x2000)
Packit 032894
    return DWARF_CB_OK;
Packit 032894
Packit 032894
  if (dwfl_addrmodule (arg, 0x2100) == NULL)
Packit 032894
    error (1, 0, "dwfl_addrmodule: %s", dwfl_errmsg (-1));
Packit 032894
Packit 032894
  return DWARF_CB_ABORT;
Packit 032894
}
Packit 032894
Packit 032894
int
Packit 032894
main (void)
Packit 032894
{
Packit 032894
  Dwfl *dwfl = dwfl_begin (&callbacks);
Packit 032894
Packit 032894
  dwfl_report_module (dwfl, "m1", 0, 0x1000);
Packit 032894
  dwfl_report_module (dwfl, "m2", 0x2000, 0x3000);
Packit 032894
  dwfl_report_module (dwfl, "m3", 0x4000, 0x5000);
Packit 032894
Packit 032894
  dwfl_report_end (dwfl, NULL, NULL);
Packit 032894
Packit 032894
  ptrdiff_t offset = dwfl_getmodules (dwfl, &iterate, dwfl, 0);
Packit 032894
  if (offset <= 0)
Packit 032894
    error (1, 0, "dwfl_getmodules: %s", dwfl_errmsg (-1));
Packit 032894
Packit 032894
  offset = dwfl_getmodules (dwfl, &iterate, NULL, offset);
Packit 032894
  if (offset != 0)
Packit 032894
    error (1, 0, "dwfl_getmodules (%d): %s", (int) offset, dwfl_errmsg (-1));
Packit 032894
Packit 032894
  dwfl_end (dwfl);
Packit 032894
Packit 032894
  return 0;
Packit 032894
}