• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2 // -*- Mode: C++ -*-
3 //
4 // Copyright (C) 2013-2021 Oracle, Inc.
5 //
6 // Author: Jose E. Marchesi
7 
8 /// @file
9 ///
10 /// This file contains the implementation of facilities to deal with
11 /// status codes related to ELF based readers.
12 ///
13 /// More generally, this file contains definitions related to
14 /// facilities shared by the various readers that handle the ELF
15 /// format, e.g, the DWARF and CTF realder.
16 #include "config.h"
17 
18 #include "abg-internal.h"
19 
20 // <headers defining libabigail's API go under here>
21 ABG_BEGIN_EXPORT_DECLARATIONS
22 
23 #include "abg-elf-reader-common.h"
24 
25 ABG_END_EXPORT_DECLARATIONS
26 // </headers defining libabigail's API>
27 
28 namespace abigail
29 {
30 
31 namespace elf_reader
32 {
33 
34 status
operator |(status l,status r)35 operator|(status l, status r)
36 {
37   return static_cast<status>(static_cast<unsigned>(l)
38 			     | static_cast<unsigned>(r));
39 }
40 
41 status
operator &(status l,status r)42 operator&(status l, status r)
43 {
44   return static_cast<status>(static_cast<unsigned>(l)
45 			     & static_cast<unsigned>(r));
46 }
47 
48 status&
operator |=(status & l,status r)49 operator|=(status& l, status r)
50 {
51   l = l | r;
52   return l;
53 }
54 
55 status&
operator &=(status & l,status r)56 operator&=(status& l, status r)
57 {
58   l = l & r;
59   return l;
60 }
61 
62 /// Return a diagnostic status with english sentences to describe the
63 /// problems encoded in a given abigail::elf_reader::status, if
64 /// there is an error.
65 ///
66 /// @param status the status to diagnose
67 ///
68 /// @return a string containing sentences that describe the possible
69 /// errors encoded in @p s.  If there is no error to encode, then the
70 /// empty string is returned.
71 std::string
status_to_diagnostic_string(status s)72 status_to_diagnostic_string(status s)
73 {
74   std::string str;
75 
76   if (s & STATUS_DEBUG_INFO_NOT_FOUND)
77     str += "could not find debug info\n";
78 
79   if (s & STATUS_ALT_DEBUG_INFO_NOT_FOUND)
80     str += "could not find alternate debug info\n";
81 
82   if (s & STATUS_NO_SYMBOLS_FOUND)
83     str += "could not load ELF symbols\n";
84 
85   return str;
86 }
87 
88 }// end namespace elf_reader
89 
90 }// end namespace abigail
91