1 /* Test program for fetching debuginfo with debuginfo-server.
2    Copyright (C) 2019 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 
19 #ifdef HAVE_CONFIG_H
20 # include <config.h>
21 #endif
22 #include <stdio.h>
23 #include ELFUTILS_HEADER(dwfl)
24 #include <elf.h>
25 #include <dwarf.h>
26 #include <argp.h>
27 #include <assert.h>
28 #include <string.h>
29 
30 static const char *debuginfo_path = "";
31 static const Dwfl_Callbacks cb  =
32   {
33     NULL,
34     dwfl_standard_find_debuginfo,
35     NULL,
36     (char **)&debuginfo_path,
37   };
38 
39 int
main(int argc,char ** argv)40 main (int argc __attribute__ ((unused)), char **argv)
41 {
42   int expect_pass = strcmp(argv[3], "0");
43   Dwarf_Addr bias = 0;
44   Dwfl *dwfl = dwfl_begin(&cb);
45   dwfl_report_begin(dwfl);
46 
47   /* Open an executable.  */
48   Dwfl_Module *mod = dwfl_report_offline(dwfl, argv[2], argv[2], -1);
49 
50   /* The corresponding debuginfo will not be found in debuginfo_path
51      (since it's empty), causing the server to be queried.  */
52 
53   Dwarf *res = dwfl_module_getdwarf(mod, &bias);
54   if (expect_pass)
55     assert(res);
56   else
57     assert(!res);
58 
59   dwfl_end (dwfl);
60 
61   return 0;
62 }
63