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 #include "debugger/rsp/rsp_control_packets.h" | |
5 | |
6 namespace rsp { | |
7 ReadMemoryCommand::ReadMemoryCommand() | |
8 : addr_(0), | |
9 num_of_bytes_(0) { | |
10 } | |
11 | |
12 // Example: "m" + "cffffff80,40" | |
13 bool ReadMemoryCommand::FromBlob(const std::string& type, | |
14 debug::Blob* message) { | |
15 std::deque<debug::Blob> tokens; | |
16 message->Split(debug::Blob().FromString(","), &tokens); | |
17 if (tokens.size() < 2) | |
18 return false; | |
19 | |
20 bool r1 = PopIntFromFront(&tokens[0], &addr_); | |
21 bool r2 = PopIntFromFront(&tokens[1], &num_of_bytes_); | |
22 return r1 && r2; | |
23 } | |
24 | |
25 void ReadMemoryCommand::ToBlob(debug::Blob* message) const { | |
26 Format(message, "m%I64x,%x", addr_, num_of_bytes_); | |
27 } | |
28 | |
29 WriteMemoryCommand::WriteMemoryCommand() | |
30 : addr_(0) { | |
31 } | |
32 | |
33 bool WriteMemoryCommand::FromBlob(const std::string& type, | |
34 debug::Blob* message) { | |
35 // example: H>[Mc00020304,1:8b] | |
36 std::deque<debug::Blob> tokens; | |
37 message->Split(debug::Blob().FromString(","), &tokens); | |
38 if (tokens.size() < 2) | |
39 return false; | |
40 | |
41 if (!PopIntFromFront(&tokens[0], &addr_)) | |
42 return false; | |
43 debug::Blob len_and_data = tokens[1]; | |
44 len_and_data.Split(debug::Blob().FromString(":"), &tokens); | |
45 if (tokens.size() < 2) | |
46 return false; | |
47 return data_.FromHexString(tokens[1].ToString()); | |
48 } | |
49 | |
50 void WriteMemoryCommand::ToBlob(debug::Blob* message) const { | |
51 std::string hex_blob = data_.ToHexStringNoLeadingZeroes(); | |
52 Format(message, "M%I64x,%x:%s", addr_, data_.size(), hex_blob.c_str()); | |
53 } | |
54 | |
55 bool WriteRegistersCommand::FromBlob(const std::string& type, | |
56 debug::Blob* message) { | |
57 return data_.FromHexString(message->ToString()); | |
58 } | |
59 | |
60 void WriteRegistersCommand::ToBlob(debug::Blob* message) const { | |
61 message->FromString("G"); | |
62 message->Append(debug::Blob().FromString(data_.ToHexString())); | |
63 } | |
64 } // namespace rsp | |
65 | |
OLD | NEW |