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

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

Issue 19870006: Support stacktrace and objecthistogram service commands (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 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 | Annotate | Revision Log
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/globals.h" 8 #include "vm/globals.h"
9 #include "vm/os.h" 9 #include "vm/os.h"
10 #include "vm/json_stream.h"
10 11
11 namespace dart { 12 namespace dart {
12 13
13 void DisassembleToStdout::ConsumeInstruction(char* hex_buffer, 14 void DisassembleToStdout::ConsumeInstruction(char* hex_buffer,
14 intptr_t hex_size, 15 intptr_t hex_size,
15 char* human_buffer, 16 char* human_buffer,
16 intptr_t human_size, 17 intptr_t human_size,
17 uword pc) { 18 uword pc) {
18 static const int kHexColumnWidth = 23; 19 static const int kHexColumnWidth = 23;
19 uint8_t* pc_ptr = reinterpret_cast<uint8_t*>(pc); 20 uint8_t* pc_ptr = reinterpret_cast<uint8_t*>(pc);
20 OS::Print("%p %s", pc_ptr, hex_buffer); 21 OS::Print("%p %s", pc_ptr, hex_buffer);
21 int hex_length = strlen(hex_buffer); 22 int hex_length = strlen(hex_buffer);
22 if (hex_length < kHexColumnWidth) { 23 if (hex_length < kHexColumnWidth) {
23 for (int i = kHexColumnWidth - hex_length; i > 0; i--) { 24 for (int i = kHexColumnWidth - hex_length; i > 0; i--) {
24 OS::Print(" "); 25 OS::Print(" ");
25 } 26 }
26 } 27 }
27 OS::Print("%s", human_buffer); 28 OS::Print("%s", human_buffer);
28 OS::Print("\n"); 29 OS::Print("\n");
29 } 30 }
30 31
31 32
32 void DisassembleToStdout::Print(const char* format, ...) { 33 void DisassembleToStdout::Print(const char* format, ...) {
33 va_list args; 34 va_list args;
34 va_start(args, format); 35 va_start(args, format);
35 OS::VFPrint(stdout, format, args); 36 OS::VFPrint(stdout, format, args);
36 va_end(args); 37 va_end(args);
37 } 38 }
38 39
40
41 void DisassembleToJSONStream::ConsumeInstruction(char* hex_buffer,
42 intptr_t hex_size,
43 char* human_buffer,
44 intptr_t human_size,
45 uword pc) {
46 uint8_t* pc_ptr = reinterpret_cast<uint8_t*>(pc);
47 stream_->OpenObject();
48 stream_->PrintProperty("type", "DisassembledInstruction");
49 stream_->PrintfProperty("pc", "%p", pc_ptr);
50 stream_->PrintProperty("hex", hex_buffer);
51 stream_->PrintProperty("human", human_buffer);
52 stream_->CloseObject();
53 }
54
55
56 void DisassembleToJSONStream::Print(const char* format, ...) {
57 va_list args;
58 va_start(args, format);
59 intptr_t len = OS::VSNPrint(NULL, 0, format, args);
60 va_end(args);
61 char* p = reinterpret_cast<char*>(malloc(len+1));
62 va_start(args, format);
63 intptr_t len2 = OS::VSNPrint(p, len, format, args);
64 va_end(args);
65 ASSERT(len == len2);
66 for (intptr_t i = 0; i < len; i++) {
67 if (p[i] == '\n' || p[i] == '\r') {
68 p[i] = ' ';
69 }
70 }
71 stream_->OpenObject();
72 stream_->PrintProperty("type", "DisassembledInstructionComment");
73 stream_->PrintProperty("comment", p);
74 stream_->CloseObject();
75 free(p);
76 }
77
39 } // namespace dart 78 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698