1 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2 // -*- Mode: C++ -*-
3 //
4 // Copyright (C) 2022 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 /// Reset (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
reset(const std::string & elf_path,const vector<char ** > & debug_info_root_paths)74 elf_based_reader::reset(const std::string& elf_path,
75 const vector<char**>& debug_info_root_paths)
76 {
77 elf::reader::reset(elf_path, debug_info_root_paths);
78 priv_->initialize();
79 }
80
81 /// Read an ABI corpus and add it to a given corpus group.
82 ///
83 /// @param group the corpus group to consider. The new corpus is
84 /// added to this group.
85 ///
86 /// @param status output parameter. This is the status of the
87 /// creation of the current ABI corpus. It's set by this function iff
88 /// a non-nil @ref corpus_sptr is returned.
89 ///
90 /// @return the resulting ABI corpus.
91 ir::corpus_sptr
read_and_add_corpus_to_group(ir::corpus_group & group,fe_iface::status & status)92 elf_based_reader::read_and_add_corpus_to_group(ir::corpus_group& group,
93 fe_iface::status& status)
94 {
95 ir::corpus_sptr corp = read_corpus(status);
96
97 if (status & fe_iface::STATUS_OK)
98 group.add_corpus(corp);
99 return corp;
100 }
101
102 } // end namespace abigail
103