Home | History | Annotate | Download | only in tests
      1 /* Test program for dwfl_getmodules bug.
      2    Copyright (C) 2008 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 ELFUTILS_HEADER(dwfl)
     28 
     29 #include <error.h>
     30 
     31 static const Dwfl_Callbacks callbacks =
     32   {
     33     .find_elf = dwfl_linux_proc_find_elf,
     34     .find_debuginfo = dwfl_standard_find_debuginfo,
     35   };
     36 
     37 static int
     38 iterate (Dwfl_Module *mod __attribute__ ((unused)),
     39 	 void **userdata __attribute__ ((unused)),
     40 	 const char *name __attribute__ ((unused)),
     41 	 Dwarf_Addr base, void *arg)
     42 {
     43   if (base != 0x2000)
     44     return DWARF_CB_OK;
     45 
     46   if (dwfl_addrmodule (arg, 0x2100) == NULL)
     47     error (1, 0, "dwfl_addrmodule: %s", dwfl_errmsg (-1));
     48 
     49   return DWARF_CB_ABORT;
     50 }
     51 
     52 int
     53 main (void)
     54 {
     55   Dwfl *dwfl = dwfl_begin (&callbacks);
     56 
     57   dwfl_report_module (dwfl, "m1", 0, 0x1000);
     58   dwfl_report_module (dwfl, "m2", 0x2000, 0x3000);
     59   dwfl_report_module (dwfl, "m3", 0x4000, 0x5000);
     60 
     61   dwfl_report_end (dwfl, NULL, NULL);
     62 
     63   ptrdiff_t offset = dwfl_getmodules (dwfl, &iterate, dwfl, 0);
     64   if (offset <= 0)
     65     error (1, 0, "dwfl_getmodules: %s", dwfl_errmsg (-1));
     66 
     67   offset = dwfl_getmodules (dwfl, &iterate, NULL, offset);
     68   if (offset != 0)
     69     error (1, 0, "dwfl_getmodules (%d): %s", (int) offset, dwfl_errmsg (-1));
     70 
     71   dwfl_end (dwfl);
     72 
     73   return 0;
     74 }
     75