| 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 JSONObject jsobj(&jsarr_); | 47 // Instructions are represented as three consecutive values in a JSON array. |
| 48 jsobj.AddProperty("type", "DisassembledInstruction"); | 48 // All three are strings. The first is the address of the instruction, |
| 49 jsobj.AddPropertyF("pc", "%p", pc_ptr); | 49 // the second is the hex string of the code, and the final is a human |
| 50 jsobj.AddProperty("hex", hex_buffer); | 50 // readable string. |
| 51 jsobj.AddProperty("human", human_buffer); | 51 jsarr_.AddValueF("%p", pc_ptr); |
| 52 jsarr_.AddValue(hex_buffer); |
| 53 jsarr_.AddValue(human_buffer); |
| 52 } | 54 } |
| 53 | 55 |
| 54 | 56 |
| 55 void DisassembleToJSONStream::Print(const char* format, ...) { | 57 void DisassembleToJSONStream::Print(const char* format, ...) { |
| 56 va_list args; | 58 va_list args; |
| 57 va_start(args, format); | 59 va_start(args, format); |
| 58 intptr_t len = OS::VSNPrint(NULL, 0, format, args); | 60 intptr_t len = OS::VSNPrint(NULL, 0, format, args); |
| 59 va_end(args); | 61 va_end(args); |
| 60 char* p = reinterpret_cast<char*>(malloc(len+1)); | 62 char* p = reinterpret_cast<char*>(malloc(len+1)); |
| 61 va_start(args, format); | 63 va_start(args, format); |
| 62 intptr_t len2 = OS::VSNPrint(p, len, format, args); | 64 intptr_t len2 = OS::VSNPrint(p, len, format, args); |
| 63 va_end(args); | 65 va_end(args); |
| 64 ASSERT(len == len2); | 66 ASSERT(len == len2); |
| 65 for (intptr_t i = 0; i < len; i++) { | 67 for (intptr_t i = 0; i < len; i++) { |
| 66 if (p[i] == '\n' || p[i] == '\r') { | 68 if (p[i] == '\n' || p[i] == '\r') { |
| 67 p[i] = ' '; | 69 p[i] = ' '; |
| 68 } | 70 } |
| 69 } | 71 } |
| 70 JSONObject jsobj(&jsarr_); | 72 // Instructions are represented as three consecutive values in a JSON array. |
| 71 jsobj.AddProperty("type", "DisassembledInstructionComment"); | 73 // All three are strings. Comments only use the third slot. See above comment |
| 72 jsobj.AddProperty("comment", p); | 74 // for more information. |
| 75 jsarr_.AddValue(""); |
| 76 jsarr_.AddValue(""); |
| 77 jsarr_.AddValue(p); |
| 73 free(p); | 78 free(p); |
| 74 } | 79 } |
| 75 | 80 |
| 76 | 81 |
| 77 class FindAddrVisitor : public FindObjectVisitor { | 82 class FindAddrVisitor : public FindObjectVisitor { |
| 78 public: | 83 public: |
| 79 explicit FindAddrVisitor(uword addr) | 84 explicit FindAddrVisitor(uword addr) |
| 80 : FindObjectVisitor(Isolate::Current()), addr_(addr) { } | 85 : FindObjectVisitor(Isolate::Current()), addr_(addr) { } |
| 81 virtual ~FindAddrVisitor() { } | 86 virtual ~FindAddrVisitor() { } |
| 82 | 87 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 93 DISALLOW_COPY_AND_ASSIGN(FindAddrVisitor); | 98 DISALLOW_COPY_AND_ASSIGN(FindAddrVisitor); |
| 94 }; | 99 }; |
| 95 | 100 |
| 96 | 101 |
| 97 bool Disassembler::CanFindOldObject(uword addr) { | 102 bool Disassembler::CanFindOldObject(uword addr) { |
| 98 FindAddrVisitor visitor(addr); | 103 FindAddrVisitor visitor(addr); |
| 99 return Isolate::Current()->heap()->FindOldObject(&visitor) != Object::null(); | 104 return Isolate::Current()->heap()->FindOldObject(&visitor) != Object::null(); |
| 100 } | 105 } |
| 101 | 106 |
| 102 } // namespace dart | 107 } // namespace dart |
| OLD | NEW |