OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 The Native Client Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 #ifndef DEBUGGER_RSP_RSP_COMMON_REPLIES_H_ | |
5 #define DEBUGGER_RSP_RSP_COMMON_REPLIES_H_ | |
6 #include <string> | |
7 #include "debugger/rsp/rsp_packets.h" | |
8 | |
9 namespace rsp { | |
10 /// Empty message can be a reply to 'm' command, or | |
11 /// can indicate that command is not supported. | |
12 /// Example: "" | |
13 class EmptyPacket : public Packet { | |
14 public: | |
15 virtual void AcceptVisitor(PacketVisitor* vis) { vis->Visit(this); } | |
16 virtual Packet* Clone() const { return new EmptyPacket; } | |
17 virtual bool FromBlob(const std::string& type, debug::Blob* message) { | |
18 return message->size() == 0; | |
19 } | |
20 virtual void ToBlob(debug::Blob* message) const { message->Clear(); } | |
21 }; | |
22 | |
23 /// Stop reply packet. | |
24 /// Examples: | |
25 /// "S05" - the program received signal number 5 | |
26 /// "T05" - the same | |
27 /// "W66" - program exited with return code 102 | |
28 /// "X12;process:1234" - program terminated due to signal 18, pid=4660 | |
29 /// "O" - program is running | |
30 class StopReply : public Packet { | |
31 public: | |
32 enum StopReason {SIGNALED, TERMINATED, EXITED, STILL_RUNNING}; | |
33 | |
34 StopReply(); | |
35 explicit StopReply(StopReason stop_reason); | |
36 | |
37 virtual Packet* Clone() const { return new StopReply(stop_reason_); } | |
38 virtual void AcceptVisitor(PacketVisitor* vis) { vis->Visit(this); } | |
39 virtual bool FromBlob(const std::string& type, debug::Blob* message); | |
40 virtual void ToBlob(debug::Blob* message) const; | |
41 | |
42 StopReason stop_reason() const { return stop_reason_; } | |
43 int signal_number() const { return signal_number_; } | |
44 int exit_code() const { return exit_code_; } | |
45 uint32_t pid() const { return pid_; } | |
46 | |
47 void set_stop_reason(StopReason x) { stop_reason_ = x; } | |
48 void set_signal_number(int x) { signal_number_ = x; } | |
49 void set_exit_code(int x) { exit_code_ = x; } | |
50 void set_pid(uint32_t x) { pid_ = x; } | |
51 | |
52 protected: | |
53 StopReason stop_reason_; | |
54 uint8_t signal_number_; | |
55 uint8_t exit_code_; | |
56 uint32_t pid_; | |
57 }; | |
58 | |
59 /// Reply to read memory request, and for read registers request. | |
60 /// Example: "554889e583ec204c01fc897dec8975e8c745" | |
61 class BlobReply : public Packet { | |
62 public: | |
63 virtual Packet* Clone() const { return new BlobReply; } | |
64 virtual void AcceptVisitor(PacketVisitor* vis) { vis->Visit(this); } | |
65 virtual bool FromBlob(const std::string& type, debug::Blob* message); | |
66 virtual void ToBlob(debug::Blob* message) const; | |
67 | |
68 const debug::Blob& data() const { return data_; } | |
69 void set_data(const debug::Blob& data) { data_ = data; } | |
70 void set_data(const void* data, size_t size) { | |
71 data_ = debug::Blob(data, size); | |
72 } | |
73 | |
74 protected: | |
75 debug::Blob data_; | |
76 }; | |
77 | |
78 /// Error reply. | |
79 /// Example: "E02" | |
80 class ErrorReply : public Packet { | |
81 public: | |
82 ErrorReply() : error_code_(0) {} | |
83 explicit ErrorReply(int code) : error_code_(code) {} | |
84 | |
85 virtual Packet* Clone() const { return new ErrorReply; } | |
86 virtual void AcceptVisitor(PacketVisitor* vis) { vis->Visit(this); } | |
87 virtual bool FromBlob(const std::string& type, debug::Blob* message) { | |
88 return PopIntFromFront(message, &error_code_); | |
89 } | |
90 virtual void ToBlob(debug::Blob* message) const { | |
91 Format(message, "E%0.2x", error_code_); | |
92 } | |
93 uint32_t error_code() const { return error_code_; } | |
94 void set_error_code(uint32_t x) { error_code_ = x; } | |
95 | |
96 protected: | |
97 uint32_t error_code_; | |
98 }; | |
99 | |
100 /// Success reply. | |
101 /// Example: "OK" | |
102 class OkReply : public OneWordPacket { | |
103 public: | |
104 OkReply() : OneWordPacket("OK") {} | |
105 virtual Packet* Clone() const { return new OkReply; } | |
106 virtual void AcceptVisitor(PacketVisitor* vis) { vis->Visit(this); } | |
107 }; | |
108 } // namespace rsp | |
109 | |
110 #endif // DEBUGGER_RSP_RSP_COMMON_REPLIES_H_ | |
111 | |
OLD | NEW |