OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/disassembler.h" | 5 #include "vm/disassembler.h" |
6 | 6 |
7 #include "vm/assembler.h" | 7 #include "vm/assembler.h" |
8 #include "vm/globals.h" | 8 #include "vm/globals.h" |
9 #include "vm/os.h" | 9 #include "vm/os.h" |
10 #include "vm/json_stream.h" | 10 #include "vm/json_stream.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 va_end(args); | 37 va_end(args); |
38 } | 38 } |
39 | 39 |
40 | 40 |
41 void DisassembleToJSONStream::ConsumeInstruction(char* hex_buffer, | 41 void DisassembleToJSONStream::ConsumeInstruction(char* hex_buffer, |
42 intptr_t hex_size, | 42 intptr_t hex_size, |
43 char* human_buffer, | 43 char* human_buffer, |
44 intptr_t human_size, | 44 intptr_t human_size, |
45 uword pc) { | 45 uword pc) { |
46 uint8_t* pc_ptr = reinterpret_cast<uint8_t*>(pc); | 46 uint8_t* pc_ptr = reinterpret_cast<uint8_t*>(pc); |
47 stream_->OpenObject(); | 47 JSONObject jsobj(jsarr_); |
48 stream_->PrintProperty("type", "DisassembledInstruction"); | 48 jsobj.AddProperty("type", "DisassembledInstruction"); |
49 stream_->PrintfProperty("pc", "%p", pc_ptr); | 49 jsobj.AddPropertyF("pc", "%p", pc_ptr); |
50 stream_->PrintProperty("hex", hex_buffer); | 50 jsobj.AddProperty("hex", hex_buffer); |
51 stream_->PrintProperty("human", human_buffer); | 51 jsobj.AddProperty("human", human_buffer); |
52 stream_->CloseObject(); | |
53 } | 52 } |
54 | 53 |
55 | 54 |
56 void DisassembleToJSONStream::Print(const char* format, ...) { | 55 void DisassembleToJSONStream::Print(const char* format, ...) { |
57 va_list args; | 56 va_list args; |
58 va_start(args, format); | 57 va_start(args, format); |
59 intptr_t len = OS::VSNPrint(NULL, 0, format, args); | 58 intptr_t len = OS::VSNPrint(NULL, 0, format, args); |
60 va_end(args); | 59 va_end(args); |
61 char* p = reinterpret_cast<char*>(malloc(len+1)); | 60 char* p = reinterpret_cast<char*>(malloc(len+1)); |
62 va_start(args, format); | 61 va_start(args, format); |
63 intptr_t len2 = OS::VSNPrint(p, len, format, args); | 62 intptr_t len2 = OS::VSNPrint(p, len, format, args); |
64 va_end(args); | 63 va_end(args); |
65 ASSERT(len == len2); | 64 ASSERT(len == len2); |
66 for (intptr_t i = 0; i < len; i++) { | 65 for (intptr_t i = 0; i < len; i++) { |
67 if (p[i] == '\n' || p[i] == '\r') { | 66 if (p[i] == '\n' || p[i] == '\r') { |
68 p[i] = ' '; | 67 p[i] = ' '; |
69 } | 68 } |
70 } | 69 } |
71 stream_->OpenObject(); | 70 JSONObject jsobj(jsarr_); |
72 stream_->PrintProperty("type", "DisassembledInstructionComment"); | 71 jsobj.AddProperty("type", "DisassembledInstructionComment"); |
73 stream_->PrintProperty("comment", p); | 72 jsobj.AddProperty("comment", p); |
74 stream_->CloseObject(); | |
75 free(p); | 73 free(p); |
76 } | 74 } |
77 | 75 |
78 } // namespace dart | 76 } // namespace dart |
OLD | NEW |