ROSE 0.11.145.147
GdbResponse.h
1#ifndef ROSE_BinaryAnalysis_Debugger_GdbResponse_H
2#define ROSE_BinaryAnalysis_Debugger_GdbResponse_H
3#include <featureTests.h>
4#ifdef ROSE_ENABLE_DEBUGGER_GDB
5#include <Rose/BinaryAnalysis/Debugger/Exception.h>
6
7#include <Rose/Yaml.h>
8
9namespace Rose {
10namespace BinaryAnalysis {
11namespace Debugger {
12
16class GdbResponse {
17
18 // Token types from the lexical analyzer
19 enum TokenType {
20 TOK_EOF, // end of file
21 TOK_LEFT, // '{' or '['
22 TOK_RIGHT, // '}' or ']'
23 TOK_DIGITS, // sequence of digits
24 TOK_SYMBOL, // sequence of letters
25 TOK_STRING, // C-style string literal
26 TOK_GDB, // the string "(gdb)"
27 TOK_OTHER // anything else
28 };
29
30 // One token from the GDB MI output langauge
31 class Token {
32 friend class TokenStream;
33 TokenType type_ = TOK_EOF;
34 size_t begin_ = 0;
35 size_t end_ = 0;
36
37 public:
38 Token();
39 Token(TokenType, size_t begin, size_t end);
40
41 TokenType type() const;
42 size_t begin() const;
43 size_t end() const;
44 size_t size() const;
45 };
46
47 // Lexical analysis and the resulting sequence of tokens.
48 class TokenStream {
49 std::string content_;
50 size_t at_ = 0;
51 std::vector<Token> tokens_;
52
53 public:
54 explicit TokenStream(const std::string &sentence)
55 : content_(sentence) {}
56
57 const Token& operator[](size_t lookahead);
58 void consume(size_t n = 1);
59 std::string lexeme(size_t lookahead) const;
60 const std::string& content() const;
61
62 private:
63 void makeNextToken();
64 };
65
66public:
68 enum class ResultClass { DONE, RUNNING, CONNECTED, ERROR, EXIT, UNSPECIFIED };
69
71 enum class AsyncClass {
72 STOPPED,
73 RUNNING,
74 THREAD_GROUP_ADDED,
75 THREAD_GROUP_STARTED,
76 THREAD_GROUP_EXITED,
77 THREAD_CREATED,
78 THREAD_EXITED,
79 BREAKPOINT_MODIFIED,
80 OTHER,
82 };
83
85 struct ResultRecord {
86 ResultClass rclass = ResultClass::UNSPECIFIED;
87 Yaml::Node results;
90 explicit operator bool() const {
91 return rclass != ResultClass::UNSPECIFIED;
92 }
93 };
94
96 struct AsyncRecord {
97 AsyncClass aclass = AsyncClass::UNSPECIFIED;
98 Yaml::Node results;
101 explicit operator bool() const {
102 return aclass != AsyncClass::UNSPECIFIED;
103 }
104 };
105
106public:
107 std::string raw;
108 bool atEnd = false;
109 std::string token;
110 ResultRecord result;
111 AsyncRecord exec;
112 AsyncRecord status;
113 AsyncRecord notify;
114 std::string console;
115 std::string target;
116 std::string log;
118public:
120 static GdbResponse parse(const std::string &line);
121
123 void print(std::ostream&) const;
124
125private:
126 // Construct an exception for a syntax error with information about the error and where it occurs.
127 static Exception syntaxError(std::string mesg, TokenStream&, size_t);
128
129 // Parsers
130 static void parseResultRecord(TokenStream&, GdbResponse&);
131 static std::pair<AsyncClass, Yaml::Node> parseAsyncOutput(TokenStream&);
132 static void parseExecAsyncOutput(TokenStream&, GdbResponse&);
133 static void parseStatusAsyncOutput(TokenStream&, GdbResponse&);
134 static void parseNotifyAsyncOutput(TokenStream&, GdbResponse&);
135 static void parseConsoleStreamOutput(TokenStream&, GdbResponse&);
136 static void parseTargetStreamOutput(TokenStream&, GdbResponse&);
137 static void parseLogStreamOutput(TokenStream&, GdbResponse&);
138 static std::pair<std::string, Yaml::Node> parseResult(TokenStream&);
139 static Yaml::Node parseValue(TokenStream&);
140
141 // Returns indented YAML unparsed from the specified node tree.
142 static std::string nodeToString(const Yaml::Node&, const std::string&);
143};
144
146std::ostream& operator<<(std::ostream&, const GdbResponse&);
147
148} // namespace
149} // namespace
150} // namespace
151
152#endif
153#endif
@ UNSPECIFIED
Stack parameter order is unknown or unspecified.
void parse(SgAsmGenericFile *)
Main function to parse DWARF information.
void print(const StackVariables &, const Partitioner2::PartitionerConstPtr &, std::ostream &out, const std::string &prefix="")
Print info about multiple local variables.
The ROSE library.
Sawyer::Language::Clexer::TokenStream TokenStream
A stream of tokens from the input file.
Sawyer::Language::Clexer::Token Token
A token parsed from the input file.
void notify(variables_map &)
Transfer map to C++ variables.
@ ERROR
Error messages that indicate an abnormal situation from which the program was able to at least partia...
Definition Message.h:330
const char * AsyncClass(int64_t)
Convert Rose::BinaryAnalysis::Debugger::GdbResponse::AsyncClass enum constant to a string.
const char * ResultClass(int64_t)
Convert Rose::BinaryAnalysis::Debugger::Gdb::Response::ResultRecord::ResultClass enum constant to a s...