retdec
exceptions.h
Go to the documentation of this file.
1 
7 #ifndef RETDEC_CAPSTONE2LLVMIR_EXCEPTIONS_H
8 #define RETDEC_CAPSTONE2LLVMIR_EXCEPTIONS_H
9 
10 #include <cassert>
11 #include <sstream>
12 #include <stdexcept>
13 
14 #include <capstone/capstone.h>
15 
16 namespace retdec {
17 namespace capstone2llvmir {
18 
23 class BaseError : public std::exception
24 {
25  public:
26  virtual ~BaseError() = default;
27 };
28 
32 class CapstoneError : public BaseError
33 {
34  public:
35  CapstoneError(cs_err e);
36 
37  std::string getMessage() const;
38  virtual const char* what() const noexcept override;
39 
40  private:
42  cs_err _csError = CS_ERR_OK;
43 };
44 
49 {
50  public:
51  enum class eType
52  {
53  UNDEF,
55  BASIC_MODE,
57  EXTRA_MODE,
60  };
61 
62  public:
63  ModeSettingError(cs_arch a, cs_mode m, eType t);
64 
65  std::string getMessage() const;
66  virtual const char* what() const noexcept override;
67 
68  private:
69  cs_arch _arch = CS_ARCH_ALL;
70  cs_mode _mode = CS_MODE_LITTLE_ENDIAN;
71  eType _type = eType::UNDEF;
72 };
73 
81 {
82  public:
88  UnexpectedOperandsError(cs_insn* i, const std::string& comment = "");
89 
90  virtual const char* what() const noexcept override;
91 
92  private:
93  cs_insn* _insn = nullptr;
94  std::string _comment;
95 };
96 
104 {
105  public:
110  UnhandledInstructionError(cs_insn* i, const std::string& comment = "");
111 
112  virtual const char* what() const noexcept override;
113 
114  private:
115  cs_insn* _insn = nullptr;
116  std::string _comment;
117 };
118 
125 class GenericError : public BaseError
126 {
127  public:
128  GenericError(const std::string& message);
129 
130  virtual const char* what() const noexcept override;
131 
132  private:
134  std::string _whatMessage;
135 };
136 
137 } // namespace capstone2llvmir
138 } // namespace retdec
139 
140 #endif
Definition: exceptions.h:24
Definition: exceptions.h:33
cs_err _csError
Capstone error.
Definition: exceptions.h:42
virtual const char * what() const noexcept override
Definition: exceptions.cpp:30
CapstoneError(cs_err e)
Definition: exceptions.cpp:19
std::string getMessage() const
Definition: exceptions.cpp:25
Definition: exceptions.h:126
std::string _whatMessage
Message returned by what() method.
Definition: exceptions.h:134
eType _type
Definition: exceptions.h:71
eType
Definition: exceptions.h:52
@ EXTRA_MODE
Extra mode cannot be used with this arch.
@ BASIC_MODE_CHANGE
Translator cannnot change basic mode for this architecture.
@ BASIC_MODE
Basic mode cannot be used with this arch.
ModeSettingError(cs_arch a, cs_mode m, eType t)
Definition: exceptions.cpp:41
std::string getMessage() const
Definition: exceptions.cpp:53
virtual const char * what() const noexcept override
Definition: exceptions.cpp:92
cs_mode _mode
Definition: exceptions.h:70
cs_arch _arch
Definition: exceptions.h:69
std::string _comment
Definition: exceptions.h:94
std::string _comment
Definition: exceptions.h:116
Definition: archive_wrapper.h:19