Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(156)

Side by Side Diff: runtime/vm/disassembler.cc

Issue 2160343003: Use the Code's pointer offsets to find object references when disassembling IA32. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: . Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/disassembler.h ('k') | runtime/vm/disassembler_arm.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/deopt_instructions.h" 8 #include "vm/deopt_instructions.h"
9 #include "vm/globals.h" 9 #include "vm/globals.h"
10 #include "vm/il_printer.h" 10 #include "vm/il_printer.h"
11 #include "vm/instructions.h" 11 #include "vm/instructions.h"
12 #include "vm/json_stream.h" 12 #include "vm/json_stream.h"
13 #include "vm/log.h" 13 #include "vm/log.h"
14 #include "vm/os.h" 14 #include "vm/os.h"
15 #include "vm/code_patcher.h" 15 #include "vm/code_patcher.h"
16 16
17 17
18 namespace dart { 18 namespace dart {
19 19
20 #ifndef PRODUCT 20 #ifndef PRODUCT
21 21
22 DECLARE_FLAG(bool, trace_inlining_intervals); 22 DECLARE_FLAG(bool, trace_inlining_intervals);
23 23
24 void DisassembleToStdout::ConsumeInstruction(const Code& code, 24 void DisassembleToStdout::ConsumeInstruction(const Code& code,
25 char* hex_buffer, 25 char* hex_buffer,
26 intptr_t hex_size, 26 intptr_t hex_size,
27 char* human_buffer, 27 char* human_buffer,
28 intptr_t human_size, 28 intptr_t human_size,
29 Object* object,
29 uword pc) { 30 uword pc) {
30 static const int kHexColumnWidth = 23; 31 static const int kHexColumnWidth = 23;
31 uint8_t* pc_ptr = reinterpret_cast<uint8_t*>(pc); 32 uint8_t* pc_ptr = reinterpret_cast<uint8_t*>(pc);
32 THR_Print("%p %s", pc_ptr, hex_buffer); 33 THR_Print("%p %s", pc_ptr, hex_buffer);
33 int hex_length = strlen(hex_buffer); 34 int hex_length = strlen(hex_buffer);
34 if (hex_length < kHexColumnWidth) { 35 if (hex_length < kHexColumnWidth) {
35 for (int i = kHexColumnWidth - hex_length; i > 0; i--) { 36 for (int i = kHexColumnWidth - hex_length; i > 0; i--) {
36 THR_Print(" "); 37 THR_Print(" ");
37 } 38 }
38 } 39 }
39 THR_Print("%s", human_buffer); 40 THR_Print("%s", human_buffer);
41 if (object != NULL) {
42 THR_Print(" %s", object->ToCString());
43 }
40 THR_Print("\n"); 44 THR_Print("\n");
41 } 45 }
42 46
43 47
44 void DisassembleToStdout::Print(const char* format, ...) { 48 void DisassembleToStdout::Print(const char* format, ...) {
45 va_list args; 49 va_list args;
46 va_start(args, format); 50 va_start(args, format);
47 THR_VPrint(format, args); 51 THR_VPrint(format, args);
48 va_end(args); 52 va_end(args);
49 } 53 }
50 54
51 55
52 void DisassembleToJSONStream::ConsumeInstruction(const Code& code, 56 void DisassembleToJSONStream::ConsumeInstruction(const Code& code,
53 char* hex_buffer, 57 char* hex_buffer,
54 intptr_t hex_size, 58 intptr_t hex_size,
55 char* human_buffer, 59 char* human_buffer,
56 intptr_t human_size, 60 intptr_t human_size,
61 Object* object,
57 uword pc) { 62 uword pc) {
58 // Instructions are represented as four consecutive values in a JSON array. 63 // Instructions are represented as four consecutive values in a JSON array.
59 // The first is the address of the instruction, the second is the hex string, 64 // The first is the address of the instruction, the second is the hex string,
60 // of the code, and the third is a human readable string, and the fourth is 65 // of the code, and the third is a human readable string, and the fourth is
61 // the object loaded by the instruction. 66 // the object loaded by the instruction.
62 jsarr_.AddValueF("%" Pp "", pc); 67 jsarr_.AddValueF("%" Pp "", pc);
63 jsarr_.AddValue(hex_buffer); 68 jsarr_.AddValue(hex_buffer);
64 jsarr_.AddValue(human_buffer); 69 jsarr_.AddValue(human_buffer);
65 70
66 Object& object = Object::Handle(); 71 if (object != NULL) {
67 if (DecodeLoadObjectFromPoolOrThread(pc, code, &object)) { 72 jsarr_.AddValue(*object);
68 jsarr_.AddValue(object);
69 } else { 73 } else {
70 jsarr_.AddValueNull(); // Not a reference to null. 74 jsarr_.AddValueNull(); // Not a reference to null.
71 } 75 }
72 } 76 }
73 77
74 78
75 void DisassembleToJSONStream::Print(const char* format, ...) { 79 void DisassembleToJSONStream::Print(const char* format, ...) {
76 va_list args; 80 va_list args;
77 va_start(args, format); 81 va_start(args, format);
78 intptr_t len = OS::VSNPrint(NULL, 0, format, args); 82 intptr_t len = OS::VSNPrint(NULL, 0, format, args);
(...skipping 11 matching lines...) Expand all
90 // Instructions are represented as four consecutive values in a JSON array. 94 // Instructions are represented as four consecutive values in a JSON array.
91 // Comments only use the third slot. See above comment for more information. 95 // Comments only use the third slot. See above comment for more information.
92 jsarr_.AddValueNull(); 96 jsarr_.AddValueNull();
93 jsarr_.AddValueNull(); 97 jsarr_.AddValueNull();
94 jsarr_.AddValue(p); 98 jsarr_.AddValue(p);
95 jsarr_.AddValueNull(); 99 jsarr_.AddValueNull();
96 free(p); 100 free(p);
97 } 101 }
98 102
99 103
100 class FindAddrVisitor : public FindObjectVisitor {
101 public:
102 explicit FindAddrVisitor(uword addr) : addr_(addr) { }
103 virtual ~FindAddrVisitor() { }
104
105 virtual uword filter_addr() const { return addr_; }
106
107 // Check if object matches find condition.
108 virtual bool FindObject(RawObject* obj) const {
109 return obj == reinterpret_cast<RawObject*>(addr_);
110 }
111
112 private:
113 const uword addr_;
114
115 DISALLOW_COPY_AND_ASSIGN(FindAddrVisitor);
116 };
117
118
119 bool Disassembler::CanFindOldObject(uword addr) {
120 FindAddrVisitor visitor(addr);
121 NoSafepointScope no_safepoint;
122 return Dart::vm_isolate()->heap()->FindOldObject(&visitor) != Object::null()
123 || Isolate::Current()->heap()->FindOldObject(&visitor) != Object::null();
124 }
125
126
127 void Disassembler::Disassemble(uword start, 104 void Disassembler::Disassemble(uword start,
128 uword end, 105 uword end,
129 DisassemblyFormatter* formatter, 106 DisassemblyFormatter* formatter,
130 const Code& code) { 107 const Code& code) {
131 const Code::Comments& comments = 108 const Code::Comments& comments =
132 code.IsNull() ? Code::Comments::New(0) : code.comments(); 109 code.IsNull() ? Code::Comments::New(0) : code.comments();
133 ASSERT(formatter != NULL); 110 ASSERT(formatter != NULL);
134 char hex_buffer[kHexadecimalBufferSize]; // Instruction in hexadecimal form. 111 char hex_buffer[kHexadecimalBufferSize]; // Instruction in hexadecimal form.
135 char human_buffer[kUserReadableBufferSize]; // Human-readable instruction. 112 char human_buffer[kUserReadableBufferSize]; // Human-readable instruction.
136 uword pc = start; 113 uword pc = start;
(...skipping 24 matching lines...) Expand all
161 } else { 138 } else {
162 f.Print(" -> %s", name); 139 f.Print(" -> %s", name);
163 } 140 }
164 } 141 }
165 if (!first) { 142 if (!first) {
166 f.Print("]\n"); 143 f.Print("]\n");
167 formatter->Print(str); 144 formatter->Print(str);
168 } 145 }
169 } 146 }
170 int instruction_length; 147 int instruction_length;
148 Object* object;
171 DecodeInstruction(hex_buffer, 149 DecodeInstruction(hex_buffer,
172 sizeof(hex_buffer), 150 sizeof(hex_buffer),
173 human_buffer, 151 human_buffer,
174 sizeof(human_buffer), 152 sizeof(human_buffer),
175 &instruction_length, pc); 153 &instruction_length, code, &object, pc);
176 formatter->ConsumeInstruction(code, 154 formatter->ConsumeInstruction(code,
177 hex_buffer, 155 hex_buffer,
178 sizeof(hex_buffer), 156 sizeof(hex_buffer),
179 human_buffer, 157 human_buffer,
180 sizeof(human_buffer), 158 sizeof(human_buffer),
159 object,
181 pc); 160 pc);
182 pc += instruction_length; 161 pc += instruction_length;
183 } 162 }
184 } 163 }
185 164
186 165
187 void Disassembler::DisassembleCodeHelper( 166 void Disassembler::DisassembleCodeHelper(
188 const char* function_fullname, const Code& code, bool optimized) { 167 const char* function_fullname, const Code& code, bool optimized) {
189 THR_Print("Code for %sfunction '%s' {\n", 168 THR_Print("Code for %sfunction '%s' {\n",
190 optimized ? "optimized " : "", 169 optimized ? "optimized " : "",
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 const Function& function, bool optimized) { 320 const Function& function, bool optimized) {
342 const char* function_fullname = function.ToFullyQualifiedCString(); 321 const char* function_fullname = function.ToFullyQualifiedCString();
343 const Code& code = Code::Handle(function.unoptimized_code()); 322 const Code& code = Code::Handle(function.unoptimized_code());
344 DisassembleCodeHelper(function_fullname, code, optimized); 323 DisassembleCodeHelper(function_fullname, code, optimized);
345 } 324 }
346 325
347 326
348 #endif // !PRODUCT 327 #endif // !PRODUCT
349 328
350 } // namespace dart 329 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/disassembler.h ('k') | runtime/vm/disassembler_arm.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698