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

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

Issue 10407019: Extend assembler with ability to produce comments for the generated code. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 7 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 #if !defined(_WIN32) // Disassembler is not yet supported under WIN32. 7 #if !defined(_WIN32) // Disassembler is not yet supported under WIN32.
8 #include <errno.h> 8 #include <errno.h>
9 #include <stdio.h> 9 #include <stdio.h>
10 #include <stdlib.h> 10 #include <stdlib.h>
11 #include <unistd.h> 11 #include <unistd.h>
12 #endif 12 #endif
13 13
14 #include "vm/globals.h" // Needed here to get TARGET_ARCH_X64. 14 #include "vm/globals.h" // Needed here to get TARGET_ARCH_X64.
15 #if defined(TARGET_ARCH_X64) 15 #if defined(TARGET_ARCH_X64)
16 #include "platform/assert.h" 16 #include "platform/assert.h"
17 17
18 namespace dart { 18 namespace dart {
19 19
20 void Disassembler::Disassemble(uword start, 20 void Disassembler::Disassemble(uword start,
21 uword end, 21 uword end,
22 DisassemblyFormatter* formatter) { 22 DisassemblyFormatter* formatter,
23 CodeComments comments) {
srdjan 2012/05/17 17:22:08 const CodeComments&
Vyacheslav Egorov (Google) 2012/05/17 21:16:27 Done.
23 // First print the actual addresses so that we know where in memory this is 24 // First print the actual addresses so that we know where in memory this is
24 // being disassembled from. 25 // being disassembled from.
25 formatter->Print("start: %p end: %p\n", start, end); 26 formatter->Print("start: %p end: %p\n", start, end);
26 27
27 #if !defined(_WIN32) // Disassembler is not yet supported under WIN32. 28 #if !defined(_WIN32) // Disassembler is not yet supported under WIN32.
28 // Write code block to tmp file. 29 // Write code block to tmp file.
29 char tmp[] = "/tmp/codeblock.XXXXXX"; 30 char tmp[] = "/tmp/codeblock.XXXXXX";
30 int fd = mkstemp(tmp); 31 int fd = mkstemp(tmp);
31 if (fd < 0) { 32 if (fd < 0) {
32 int errsv = errno; 33 int errsv = errno;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 #else 76 #else
76 const char* header = "<.data>:\n"; 77 const char* header = "<.data>:\n";
77 #endif 78 #endif
78 char* header_pos = NULL; 79 char* header_pos = NULL;
79 while (header_pos == NULL && fgets(line, sizeof(line), output) != NULL) { 80 while (header_pos == NULL && fgets(line, sizeof(line), output) != NULL) {
80 header_pos = strstr(line, header); 81 header_pos = strstr(line, header);
81 if (header_pos != NULL) { 82 if (header_pos != NULL) {
82 formatter->Print("%s", header_pos + strlen(header)); 83 formatter->Print("%s", header_pos + strlen(header));
83 } 84 }
84 } 85 }
86
87
88 int comment_finger = 0;
85 while (fgets(line, sizeof(line), output) != NULL) { 89 while (fgets(line, sizeof(line), output) != NULL) {
86 formatter->Print("%s", line); 90 char* tab = strchr(line, '\t');
91 if (tab != NULL) {
92 *tab = '\0';
93 intptr_t offset = 0;
94 sscanf(line, "%p", reinterpret_cast<void**>(&offset)); // NOLINT
95 while (comment_finger < comments.Length() &&
96 comments.PCAt(comment_finger) <= offset) {
97 formatter->Print(" ;; %s\n",
98 comments.CommentAt(comment_finger).ToCString());
99 comment_finger++;
100 }
101
102 formatter->Print("%016p %08x %s", start + offset, offset, tab + 1);
103 }
87 } 104 }
88 pclose(output); 105 pclose(output);
89 106
90 // Delete tmp files. 107 // Delete tmp files.
91 remove(tmp); 108 remove(tmp);
92 #if defined(__APPLE__) 109 #if defined(__APPLE__)
93 char tmp_o[32]; 110 char tmp_o[32];
94 snprintf(tmp_o, sizeof(tmp_o), "%s.o", tmp); 111 snprintf(tmp_o, sizeof(tmp_o), "%s.o", tmp);
95 remove(tmp_o); 112 remove(tmp_o);
96 #endif 113 #endif
97 #endif // !defined(_WIN32) 114 #endif // !defined(_WIN32)
98 } 115 }
99 116
100 117
101 int Disassembler::DecodeInstruction(char* hexa_buffer, intptr_t hexa_size, 118 int Disassembler::DecodeInstruction(char* hexa_buffer, intptr_t hexa_size,
102 char* human_buffer, intptr_t human_size, 119 char* human_buffer, intptr_t human_size,
103 uword pc) { 120 uword pc) {
104 UNIMPLEMENTED(); 121 UNIMPLEMENTED();
105 return 0; 122 return 0;
106 } 123 }
107 124
108 } // namespace dart 125 } // namespace dart
109 126
110 #endif // defined TARGET_ARCH_X64 127 #endif // defined TARGET_ARCH_X64
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698