• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2 // -*- Mode: C++ -*-
3 //
4 // Copyright (C) 2013-2020 Red Hat, Inc.
5 //
6 // Author: Dodji Seketeli
7 
8 /// @file
9 ///
10 /// This file contains the declarations of the entry points to
11 /// de-serialize an instance of @ref abigail::corpus from a file in
12 /// elf format, containing dwarf information.
13 
14 #ifndef __ABG_DWARF_READER_H__
15 #define __ABG_DWARF_READER_H__
16 
17 #include <ostream>
18 #include <elfutils/libdwfl.h>
19 #include "abg-corpus.h"
20 #include "abg-suppression.h"
21 #include "abg-elf-reader-common.h"
22 
23 namespace abigail
24 {
25 
26 /// The namespace for the DWARF reader.
27 namespace dwarf_reader
28 {
29 
30 using namespace abigail::ir;
31 
32 /// The kind of ELF file we are looking at.
33 enum elf_type
34 {
35   /// A normal executable binary
36   ELF_TYPE_EXEC,
37   /// A Position Independant Executable binary
38   ELF_TYPE_PI_EXEC,
39   /// A dynamic shared object, a.k.a shared library binrary.
40   ELF_TYPE_DSO,
41   /// A relocatalbe binary.
42   ELF_TYPE_RELOCATABLE,
43   /// An unknown kind of binary.
44   ELF_TYPE_UNKNOWN
45 };
46 
47 class read_context;
48 
49 /// A convenience typedef for a smart pointer to a
50 /// dwarf_reader::read_context.
51 typedef shared_ptr<read_context> read_context_sptr;
52 
53 read_context_sptr
54 create_read_context(const std::string&	elf_path,
55 		    const vector<char**>& debug_info_root_paths,
56 		    ir::environment*	environment,
57 		    bool		read_all_types = false,
58 		    bool		linux_kernel_mode = false);
59 
60 const string&
61 read_context_get_path(const read_context&);
62 
63 void
64 reset_read_context(read_context_sptr &ctxt,
65 		   const std::string&	elf_path,
66 		   const vector<char**>& debug_info_root_paths,
67 		   ir::environment*	environment,
68 		   bool		read_all_types = false,
69 		   bool		linux_kernel_mode = false);
70 
71 void
72 add_read_context_suppressions(read_context& ctxt,
73 			      const suppr::suppressions_type& supprs);
74 
75 void
76 set_read_context_corpus_group(read_context& ctxt, corpus_group_sptr& group);
77 
78 corpus_sptr
79 read_corpus_from_elf(read_context& ctxt, elf_reader::status& stat);
80 
81 corpus_sptr
82 read_corpus_from_elf(const std::string& elf_path,
83 		     const vector<char**>& debug_info_root_paths,
84 		     ir::environment*	environment,
85 		     bool		load_all_types,
86 		     elf_reader::status&);
87 
88 corpus_sptr
89 read_and_add_corpus_to_group_from_elf(read_context&, corpus_group&, elf_reader::status&);
90 
91 bool
92 lookup_symbol_from_elf(const environment*		env,
93 		       const string&			elf_path,
94 		       const string&			symbol_name,
95 		       bool				demangle,
96 		       vector<elf_symbol_sptr>&	symbols);
97 
98 bool
99 lookup_public_function_symbol_from_elf(const environment*		env,
100 				       const string&			path,
101 				       const string&			symname,
102 				       vector<elf_symbol_sptr>&	func_syms);
103 
104 bool
105 refers_to_alt_debug_info(const read_context&	ctxt,
106 			 string&		alt_di_path);
107 
108 elf_reader::status
109 has_alt_debug_info(read_context&	ctxt,
110 		   bool&		has_alt_di,
111 		   string&		alt_debug_info_path);
112 
113 elf_reader::status
114 has_alt_debug_info(const string&	elf_path,
115 		   char**		debug_info_root_path,
116 		   bool&		has_alt_di,
117 		   string&		alt_debug_info_path);
118 
119 bool
120 get_soname_of_elf_file(const string& path, string& soname);
121 
122 bool
123 get_type_of_elf_file(const string& path, elf_type& type);
124 
125 
126 void
127 set_debug_info_root_path(read_context& ctxt,
128 			 char** path);
129 
130 char**
131 get_debug_info_root_path(read_context& ctxt,
132 			 char**& path);
133 
134 bool
135 get_show_stats(read_context& ctxt);
136 
137 void
138 set_show_stats(read_context& ctxt,
139 	       bool f);
140 
141 void
142 set_drop_undefined_syms(read_context& ctxt,
143 			bool f);
144 
145 void
146 set_do_log(read_context& ctxt, bool f);
147 
148 void
149 set_environment(read_context& ctxt,
150 		ir::environment*);
151 
152 const environment_sptr&
153 get_environment(const read_context& ctxt);
154 
155 environment_sptr&
156 get_environment(read_context& ctxt);
157 }// end namespace dwarf_reader
158 
159 }// end namespace abigail
160 
161 #endif //__ABG_DWARF_READER_H__
162