• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2 // -*- Mode: C++ -*-
3 //
4 // Copyright (C) 2022-2023 Red Hat, Inc.
5 //
6 // Author: Dodji Seketeli
7 
8 /// @file
9 ///
10 /// This file contains the definitions of the entry points of the
11 /// generic interface for ELF-based front-ends.  The generic interface
12 /// for ELF-based front-ends is named @ref elf_based_reader.  Examples
13 /// of front-ends that implement that interface are @ref
14 /// abigail::dwarf_reader::reader and abigail::ctf_raeder::reader.
15 
16 #include "abg-internal.h"
17 
18 // <headers defining libabigail's API go under here>
19 ABG_BEGIN_EXPORT_DECLARATIONS
20 
21 #include "abg-elf-based-reader.h"
22 
23 ABG_END_EXPORT_DECLARATIONS
24 // </headers defining libabigail's API>
25 namespace abigail
26 {
27 
28 /// The private data of the @ref elf_based_reader type.
29 struct elf_based_reader::priv
30 {
31 
32   void
initializeabigail::elf_based_reader::priv33   initialize()
34   {
35   }
36 
privabigail::elf_based_reader::priv37   priv()
38   {
39     initialize();
40   }
41 }; // end struct elf_based_reader::priv
42 
43 /// Constructor of the @erf elf_based_reader type.
44 ///
45 /// @param elf_path the path the ELF file to read.
46 ///
47 /// @param debug_info_root_paths a vector of paths to look into for
48 /// split debug info files.
49 ///
50 /// @param env the environment used by the reader.
elf_based_reader(const std::string & elf_path,const vector<char ** > & debug_info_root_paths,environment & env)51 elf_based_reader::elf_based_reader(const std::string& elf_path,
52 				   const vector<char**>& debug_info_root_paths,
53 				   environment& env)
54   : elf::reader(elf_path, debug_info_root_paths, env),
55     priv_(new priv)
56 {
57   priv_->initialize();
58 }
59 
60 /// Destructor of the reader.
~elf_based_reader()61 elf_based_reader::~elf_based_reader()
62 {delete priv_;}
63 
64 /// (re)Initialize) the resources used by the current reader.
65 ///
66 /// This frees the resources of the current reader and gets it ready
67 /// to read data from another ELF file.
68 ///
69 /// @param elf_path the path to the new ELF file to consider.
70 ///
71 /// @param debug_info_root_paths a vector of paths to look into for
72 /// split debug info files.
73 void
initialize(const std::string & elf_path,const vector<char ** > & debug_info_root_paths)74 elf_based_reader::initialize(const std::string& elf_path,
75 			     const vector<char**>& debug_info_root_paths)
76 {
77   elf::reader::initialize(elf_path, debug_info_root_paths);
78   priv_->initialize();
79 }
80 
81 /// (re)Initialize the resources used by the current reader.
82 ///
83 /// This invokes fe_iface::initialize as wel as the virtual pure
84 /// elf_based_reader::initialize() interface.
85 ///
86 /// @param corpus_path path to the corpus to be built.
87 void
initialize(const std::string & corpus_path)88 elf_based_reader::initialize(const std::string& corpus_path)
89 {
90   fe_iface::initialize(corpus_path);
91   vector<char**> v;
92   initialize(corpus_path, v, /*load_all_type=*/false,
93 	     /*linux_kernel_mode=*/false);
94 }
95 
96 /// Read an ABI corpus and add it to a given corpus group.
97 ///
98 /// @param group the corpus group to consider.  The new corpus is
99 /// added to this group.
100 ///
101 /// @param status output parameter.  This is the status of the
102 /// creation of the current ABI corpus.  It's set by this function iff
103 /// a non-nil @ref corpus_sptr is returned.
104 ///
105 /// @return the resulting ABI corpus.
106 ir::corpus_sptr
read_and_add_corpus_to_group(ir::corpus_group & group,fe_iface::status & status)107 elf_based_reader::read_and_add_corpus_to_group(ir::corpus_group& group,
108 					       fe_iface::status& status)
109 {
110   group.add_corpus(corpus());
111   ir::corpus_sptr corp = read_corpus(status);
112   return corp;
113 }
114 
115 } // end namespace abigail
116