OLD | NEW |
| (Empty) |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | |
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. | |
4 | |
5 #include "vm/dwarf.h" | |
6 | |
7 #include "vm/code_descriptors.h" | |
8 #include "vm/object_store.h" | |
9 | |
10 namespace dart { | |
11 | |
12 #ifdef DART_PRECOMPILER | |
13 | |
14 #if defined(ARCH_IS_32_BIT) | |
15 #define FORM_ADDR ".4byte" | |
16 #elif defined(ARCH_IS_64_BIT) | |
17 #define FORM_ADDR ".8byte" | |
18 #endif | |
19 | |
20 class InliningNode : public ZoneAllocated { | |
21 public: | |
22 InliningNode(const Function& function, | |
23 TokenPosition call_pos, | |
24 int32_t start_pc_offset) | |
25 : function(function), | |
26 call_pos(call_pos), | |
27 start_pc_offset(start_pc_offset), | |
28 end_pc_offset(-1), | |
29 children_head(NULL), | |
30 children_tail(NULL), | |
31 children_next(NULL) {} | |
32 | |
33 void AppendChild(InliningNode* child) { | |
34 if (children_tail == NULL) { | |
35 children_head = children_tail = child; | |
36 } else { | |
37 children_tail->children_next = child; | |
38 children_tail = child; | |
39 } | |
40 } | |
41 | |
42 const Function& function; | |
43 TokenPosition call_pos; | |
44 int32_t start_pc_offset; | |
45 int32_t end_pc_offset; | |
46 InliningNode* children_head; | |
47 InliningNode* children_tail; | |
48 InliningNode* children_next; | |
49 }; | |
50 | |
51 | |
52 Dwarf::Dwarf(Zone* zone, WriteStream* stream) | |
53 : zone_(zone), | |
54 stream_(stream), | |
55 codes_(zone, 1024), | |
56 code_to_index_(zone), | |
57 functions_(zone, 1024), | |
58 function_to_index_(zone), | |
59 scripts_(zone, 1024), | |
60 script_to_index_(zone), | |
61 temp_(0) {} | |
62 | |
63 | |
64 intptr_t Dwarf::AddCode(const Code& code) { | |
65 ASSERT(!code.IsNull()); | |
66 CodeIndexPair* pair = code_to_index_.Lookup(&code); | |
67 if (pair != NULL) { | |
68 return pair->index_; | |
69 } | |
70 intptr_t index = codes_.length(); | |
71 const Code& zone_code = Code::ZoneHandle(zone_, code.raw()); | |
72 code_to_index_.Insert(CodeIndexPair(&zone_code, index)); | |
73 codes_.Add(&zone_code); | |
74 if (code.IsFunctionCode()) { | |
75 const Function& function = Function::Handle(zone_, code.function()); | |
76 AddFunction(function); | |
77 } | |
78 const Array& inline_functions = | |
79 Array::Handle(zone_, code.inlined_id_to_function()); | |
80 if (!inline_functions.IsNull()) { | |
81 Function& function = Function::Handle(zone_); | |
82 for (intptr_t i = 0; i < inline_functions.Length(); i++) { | |
83 function ^= inline_functions.At(i); | |
84 AddFunction(function); | |
85 } | |
86 } | |
87 return index; | |
88 } | |
89 | |
90 | |
91 intptr_t Dwarf::AddFunction(const Function& function) { | |
92 ASSERT(!function.IsNull()); | |
93 FunctionIndexPair* pair = function_to_index_.Lookup(&function); | |
94 if (pair != NULL) { | |
95 return pair->index_; | |
96 } | |
97 intptr_t index = functions_.length(); | |
98 const Function& zone_func = Function::ZoneHandle(zone_, function.raw()); | |
99 function_to_index_.Insert(FunctionIndexPair(&zone_func, index)); | |
100 functions_.Add(&zone_func); | |
101 const Script& script = Script::Handle(zone_, function.script()); | |
102 AddScript(script); | |
103 return index; | |
104 } | |
105 | |
106 | |
107 intptr_t Dwarf::AddScript(const Script& script) { | |
108 ASSERT(!script.IsNull()); | |
109 ScriptIndexPair* pair = script_to_index_.Lookup(&script); | |
110 if (pair != NULL) { | |
111 return pair->index_; | |
112 } | |
113 // DWARF file numbers start from 1. | |
114 intptr_t index = scripts_.length() + 1; | |
115 const Script& zone_script = Script::ZoneHandle(zone_, script.raw()); | |
116 script_to_index_.Insert(ScriptIndexPair(&zone_script, index)); | |
117 scripts_.Add(&zone_script); | |
118 return index; | |
119 } | |
120 | |
121 | |
122 intptr_t Dwarf::LookupFunction(const Function& function) { | |
123 ASSERT(!function.IsNull()); | |
124 FunctionIndexPair* pair = function_to_index_.Lookup(&function); | |
125 if (pair == NULL) { | |
126 FATAL1("Function detected too late during DWARF generation: %s", | |
127 function.ToCString()); | |
128 } | |
129 return pair->index_; | |
130 } | |
131 | |
132 | |
133 intptr_t Dwarf::LookupScript(const Script& script) { | |
134 ASSERT(!script.IsNull()); | |
135 ScriptIndexPair* pair = script_to_index_.Lookup(&script); | |
136 if (pair == NULL) { | |
137 FATAL1("Script detected too late during DWARF generation: %s", | |
138 script.ToCString()); | |
139 } | |
140 return pair->index_; | |
141 } | |
142 | |
143 | |
144 void Dwarf::Print(const char* format, ...) { | |
145 va_list args; | |
146 va_start(args, format); | |
147 stream_->VPrint(format, args); | |
148 va_end(args); | |
149 } | |
150 | |
151 | |
152 void Dwarf::WriteAbbreviations() { | |
153 // Dwarf data mostly takes the form of a tree, whose nodes are called | |
154 // DIEs. Each DIE begins with an abbreviation code, and the abbreviation | |
155 // describes the attributes of that DIE and their representation. | |
156 | |
157 #if defined(HOST_OS_MACOS) | |
158 Print(".section __DWARF,__debug_abbrev,regular,debug\n"); | |
159 #else | |
160 Print(".section .debug_abbrev,\"\"\n"); | |
161 #endif | |
162 | |
163 uleb128(kCompilationUnit); // Abbrev code. | |
164 uleb128(DW_TAG_compile_unit); // Type. | |
165 u1(DW_CHILDREN_yes); | |
166 uleb128(DW_AT_name); // Start of attributes. | |
167 uleb128(DW_FORM_string); | |
168 uleb128(DW_AT_producer); | |
169 uleb128(DW_FORM_string); | |
170 uleb128(DW_AT_comp_dir); | |
171 uleb128(DW_FORM_string); | |
172 uleb128(DW_AT_low_pc); | |
173 uleb128(DW_FORM_addr); | |
174 uleb128(DW_AT_high_pc); | |
175 uleb128(DW_FORM_addr); | |
176 uleb128(DW_AT_stmt_list); | |
177 uleb128(DW_FORM_sec_offset); | |
178 uleb128(0); | |
179 uleb128(0); // End of attributes. | |
180 | |
181 uleb128(kAbstractFunction); // Abbrev code. | |
182 uleb128(DW_TAG_subprogram); // Type. | |
183 u1(DW_CHILDREN_yes); | |
184 uleb128(DW_AT_name); // Start of attributes. | |
185 uleb128(DW_FORM_string); | |
186 uleb128(DW_AT_decl_file); | |
187 uleb128(DW_FORM_udata); | |
188 uleb128(DW_AT_decl_line); | |
189 uleb128(DW_FORM_udata); | |
190 uleb128(DW_AT_inline); | |
191 uleb128(DW_FORM_udata); | |
192 uleb128(0); | |
193 uleb128(0); // End of attributes. | |
194 | |
195 uleb128(kConcreteFunction); // Abbrev code. | |
196 uleb128(DW_TAG_subprogram); // Type. | |
197 u1(DW_CHILDREN_yes); | |
198 uleb128(DW_AT_abstract_origin); // Start of attributes. | |
199 uleb128(DW_FORM_ref4); | |
200 uleb128(DW_AT_low_pc); | |
201 uleb128(DW_FORM_addr); | |
202 uleb128(DW_AT_high_pc); | |
203 uleb128(DW_FORM_addr); | |
204 uleb128(0); | |
205 uleb128(0); // End of attributes. | |
206 | |
207 uleb128(kInlinedFunction); // Abbrev code. | |
208 uleb128(DW_TAG_inlined_subroutine); // Type. | |
209 u1(DW_CHILDREN_yes); | |
210 uleb128(DW_AT_abstract_origin); // Start of attributes. | |
211 uleb128(DW_FORM_ref4); | |
212 uleb128(DW_AT_low_pc); | |
213 uleb128(DW_FORM_addr); | |
214 uleb128(DW_AT_high_pc); | |
215 uleb128(DW_FORM_addr); | |
216 uleb128(DW_AT_call_file); | |
217 uleb128(DW_FORM_udata); | |
218 uleb128(DW_AT_call_line); | |
219 uleb128(DW_FORM_udata); | |
220 uleb128(0); | |
221 uleb128(0); // End of attributes. | |
222 | |
223 uleb128(0); // End of abbreviations. | |
224 } | |
225 | |
226 | |
227 void Dwarf::WriteCompilationUnit() { | |
228 // 7.5.1.1 Compilation Unit Header | |
229 | |
230 #if defined(HOST_OS_MACOS) | |
231 Print(".section __DWARF,__debug_info,regular,debug\n"); | |
232 #else | |
233 Print(".section .debug_info,\"\"\n"); | |
234 #endif | |
235 Print(".Ldebug_info:\n"); | |
236 | |
237 // Unit length. Assignment to temp works around buggy Mac assembler. | |
238 Print("Lcu_size = .Lcu_end - .Lcu_start\n"); | |
239 Print(".4byte Lcu_size\n"); | |
240 Print(".Lcu_start:\n"); | |
241 | |
242 u2(2); // DWARF version 2 | |
243 u4(0); // debug_abbrev_offset | |
244 u1(sizeof(void*)); // address_size | |
245 | |
246 // Compilation Unit DIE. We describe the entire Dart program as a single | |
247 // compilation unit. Note we write attributes in the same order we declared | |
248 // them in our abbreviation above in WriteAbbreviations. | |
249 uleb128(kCompilationUnit); | |
250 const Library& root_library = Library::Handle( | |
251 zone_, Isolate::Current()->object_store()->root_library()); | |
252 const String& root_uri = String::Handle(zone_, root_library.url()); | |
253 Print(".string \"%s\"\n", root_uri.ToCString()); // DW_AT_name | |
254 Print(".string \"Dart VM\"\n"); // DW_AT_producer | |
255 Print(".string \"\"\n"); // DW_AT_comp_dir | |
256 | |
257 // DW_AT_low_pc | |
258 // The lowest instruction address in this object file that is part of our | |
259 // compilation unit. Dwarf consumers use this to quickly decide which | |
260 // compilation unit DIE to consult for a given pc. | |
261 Print(FORM_ADDR " _kDartIsolateSnapshotInstructions\n"); | |
262 | |
263 // DW_AT_high_pc | |
264 // The highest instruction address in this object file that is part of our | |
265 // compilation unit. Dwarf consumers use this to quickly decide which | |
266 // compilation unit DIE to consult for a given pc. | |
267 intptr_t last_code_index = codes_.length() - 1; | |
268 const Code& last_code = *(codes_[last_code_index]); | |
269 Print(FORM_ADDR " .Lcode%" Pd " + %" Pd "\n", last_code_index, | |
270 last_code.Size()); | |
271 | |
272 // DW_AT_stmt_list (offset into .debug_line) | |
273 // Indicates which line number program is associated with this compilation | |
274 // unit. We only emit a single line number program. | |
275 u4(0); | |
276 | |
277 WriteAbstractFunctions(); | |
278 WriteConcreteFunctions(); | |
279 | |
280 uleb128(0); // End of children. | |
281 | |
282 uleb128(0); // End of entries. | |
283 Print(".Lcu_end:\n"); | |
284 } | |
285 | |
286 | |
287 void Dwarf::WriteAbstractFunctions() { | |
288 Script& script = Script::Handle(zone_); | |
289 String& name = String::Handle(zone_); | |
290 for (intptr_t i = 0; i < functions_.length(); i++) { | |
291 const Function& function = *(functions_[i]); | |
292 name = function.QualifiedUserVisibleName(); | |
293 script = function.script(); | |
294 intptr_t file = LookupScript(script); | |
295 intptr_t line = 0; // Not known. Script has already lost its token stream. | |
296 | |
297 Print(".Lfunc%" Pd ":\n", i); // Label for DW_AT_abstract_origin references | |
298 uleb128(kAbstractFunction); | |
299 Print(".string \"%s\"\n", name.ToCString()); // DW_AT_name | |
300 uleb128(file); // DW_AT_decl_file | |
301 uleb128(line); // DW_AT_decl_line | |
302 uleb128(DW_INL_inlined); // DW_AT_inline | |
303 uleb128(0); // End of children. | |
304 } | |
305 } | |
306 | |
307 | |
308 void Dwarf::WriteConcreteFunctions() { | |
309 Function& function = Function::Handle(zone_); | |
310 Script& script = Script::Handle(zone_); | |
311 for (intptr_t i = 0; i < codes_.length(); i++) { | |
312 const Code& code = *(codes_[i]); | |
313 if (!code.IsFunctionCode()) { | |
314 continue; | |
315 } | |
316 function = code.function(); | |
317 intptr_t function_index = LookupFunction(function); | |
318 script = function.script(); | |
319 | |
320 uleb128(kConcreteFunction); | |
321 // DW_AT_abstract_origin | |
322 // References a node written above in WriteAbstractFunctions. | |
323 // Assignment to temp works around buggy Mac assembler. | |
324 intptr_t temp = temp_++; | |
325 Print("Ltemp%" Pd " = .Lfunc%" Pd " - .Ldebug_info\n", temp, | |
326 function_index); | |
327 Print(".4byte Ltemp%" Pd "\n", temp); | |
328 | |
329 // DW_AT_low_pc | |
330 Print(FORM_ADDR " .Lcode%" Pd "\n", i); | |
331 // DW_AT_high_pc | |
332 Print(FORM_ADDR " .Lcode%" Pd " + %" Pd "\n", i, code.Size()); | |
333 | |
334 InliningNode* node = ExpandInliningTree(code); | |
335 if (node != NULL) { | |
336 for (InliningNode* child = node->children_head; child != NULL; | |
337 child = child->children_next) { | |
338 WriteInliningNode(child, i, script); | |
339 } | |
340 } | |
341 | |
342 uleb128(0); // End of children. | |
343 } | |
344 } | |
345 | |
346 | |
347 // Our state machine encodes position metadata such that we don't know the | |
348 // end pc for an inlined function until it is popped, but DWARF DIEs encode | |
349 // it where the function is pushed. We expand the state transitions into | |
350 // an in-memory tree to do the conversion. | |
351 InliningNode* Dwarf::ExpandInliningTree(const Code& code) { | |
352 const CodeSourceMap& map = | |
353 CodeSourceMap::Handle(zone_, code.code_source_map()); | |
354 if (map.IsNull()) { | |
355 return NULL; | |
356 } | |
357 const Array& functions = Array::Handle(zone_, code.inlined_id_to_function()); | |
358 const Function& root_function = Function::Handle(zone_, code.function()); | |
359 | |
360 GrowableArray<InliningNode*> node_stack(zone_, 4); | |
361 GrowableArray<TokenPosition> token_positions(zone_, 4); | |
362 | |
363 NoSafepointScope no_safepoint; | |
364 ReadStream stream(map.Data(), map.Length()); | |
365 | |
366 int32_t current_pc_offset = 0; | |
367 InliningNode* root_node = | |
368 new (zone_) InliningNode(root_function, TokenPosition(), 0); | |
369 root_node->end_pc_offset = code.Size(); | |
370 node_stack.Add(root_node); | |
371 token_positions.Add(CodeSourceMapBuilder::kInitialPosition); | |
372 | |
373 while (stream.PendingBytes() > 0) { | |
374 uint8_t opcode = stream.Read<uint8_t>(); | |
375 switch (opcode) { | |
376 case CodeSourceMapBuilder::kChangePosition: { | |
377 int32_t position = stream.Read<int32_t>(); | |
378 token_positions[token_positions.length() - 1] = TokenPosition(position); | |
379 break; | |
380 } | |
381 case CodeSourceMapBuilder::kAdvancePC: { | |
382 int32_t delta = stream.Read<int32_t>(); | |
383 current_pc_offset += delta; | |
384 break; | |
385 } | |
386 case CodeSourceMapBuilder::kPushFunction: { | |
387 int32_t func = stream.Read<int32_t>(); | |
388 const Function& child_func = | |
389 Function::Handle(zone_, Function::RawCast(functions.At(func))); | |
390 TokenPosition call_pos = token_positions.Last(); | |
391 InliningNode* child_node = | |
392 new (zone_) InliningNode(child_func, call_pos, current_pc_offset); | |
393 node_stack.Last()->AppendChild(child_node); | |
394 node_stack.Add(child_node); | |
395 token_positions.Add(CodeSourceMapBuilder::kInitialPosition); | |
396 break; | |
397 } | |
398 case CodeSourceMapBuilder::kPopFunction: { | |
399 // We never pop the root function. | |
400 ASSERT(node_stack.length() > 1); | |
401 ASSERT(token_positions.length() > 1); | |
402 node_stack.Last()->end_pc_offset = current_pc_offset; | |
403 node_stack.RemoveLast(); | |
404 token_positions.RemoveLast(); | |
405 break; | |
406 } | |
407 default: | |
408 UNREACHABLE(); | |
409 } | |
410 } | |
411 | |
412 while (node_stack.length() > 1) { | |
413 node_stack.Last()->end_pc_offset = current_pc_offset; | |
414 node_stack.RemoveLast(); | |
415 token_positions.RemoveLast(); | |
416 } | |
417 ASSERT(node_stack[0] == root_node); | |
418 return root_node; | |
419 } | |
420 | |
421 | |
422 void Dwarf::WriteInliningNode(InliningNode* node, | |
423 intptr_t root_code_index, | |
424 const Script& parent_script) { | |
425 intptr_t file = LookupScript(parent_script); | |
426 intptr_t line = node->call_pos.value(); | |
427 intptr_t function_index = LookupFunction(node->function); | |
428 const Script& script = Script::Handle(zone_, node->function.script()); | |
429 | |
430 uleb128(kInlinedFunction); | |
431 // DW_AT_abstract_origin | |
432 // References a node written above in WriteAbstractFunctions. | |
433 // Assignment to temp works around buggy Mac assembler. | |
434 intptr_t temp = temp_++; | |
435 Print("Ltemp%" Pd " = .Lfunc%" Pd " - .Ldebug_info\n", temp, function_index); | |
436 Print(".4byte Ltemp%" Pd "\n", temp); | |
437 // DW_AT_low_pc | |
438 Print(FORM_ADDR " .Lcode%" Pd " + %" Pd "\n", root_code_index, | |
439 node->start_pc_offset); | |
440 // DW_AT_high_pc | |
441 Print(FORM_ADDR " .Lcode%" Pd " + %" Pd "\n", root_code_index, | |
442 node->end_pc_offset); | |
443 // DW_AT_call_file | |
444 uleb128(file); | |
445 // DW_AT_call_line | |
446 uleb128(line); | |
447 | |
448 for (InliningNode* child = node->children_head; child != NULL; | |
449 child = child->children_next) { | |
450 WriteInliningNode(child, root_code_index, script); | |
451 } | |
452 | |
453 uleb128(0); // End of children. | |
454 } | |
455 | |
456 | |
457 void Dwarf::WriteLines() { | |
458 #if defined(HOST_OS_MACOS) | |
459 Print(".section __DWARF,__debug_line,regular,debug\n"); | |
460 #else | |
461 Print(".section .debug_line,\"\"\n"); | |
462 #endif | |
463 | |
464 // 6.2.4 The Line Number Program Header | |
465 | |
466 // 1. unit_length. This encoding implies 32-bit DWARF. | |
467 Print("Lline_size = .Lline_end - .Lline_start\n"); | |
468 Print(".4byte Lline_size\n"); | |
469 | |
470 Print(".Lline_start:\n"); | |
471 | |
472 u2(2); // 2. DWARF version 2 | |
473 | |
474 // 3. header_length | |
475 // Assignment to temp works around buggy Mac assembler. | |
476 Print("Llineheader_size = .Llineheader_end - .Llineheader_start\n"); | |
477 Print(".4byte Llineheader_size\n"); | |
478 Print(".Llineheader_start:\n"); | |
479 | |
480 u1(1); // 4. minimum_instruction_length | |
481 u1(0); // 5. default_is_stmt | |
482 u1(0); // 6. line_base | |
483 u1(1); // 7. line_range | |
484 u1(13); // 8. opcode_base (12 standard opcodes in Dwarf 2) | |
485 | |
486 // 9. standard_opcode_lengths | |
487 u1(0); // DW_LNS_copy, 0 operands | |
488 u1(1); // DW_LNS_advance_pc, 1 operands | |
489 u1(1); // DW_LNS_advance_list, 1 operands | |
490 u1(1); // DW_LNS_set_file, 1 operands | |
491 u1(1); // DW_LNS_set_column, 1 operands | |
492 u1(0); // DW_LNS_negate_stmt, 0 operands | |
493 u1(0); // DW_LNS_set_basic_block, 0 operands | |
494 u1(0); // DW_LNS_const_add_pc, 0 operands | |
495 u1(1); // DW_LNS_fixed_advance_pc, 1 operands | |
496 u1(0); // DW_LNS_set_prolog_end, 0 operands | |
497 u1(0); // DW_LNS_set_epligoue_begin, 0 operands | |
498 u1(1); // DW_LNS_set_isa, 1 operands | |
499 | |
500 // 10. include_directories (sequence of path names) | |
501 // We don't emit any because we use full paths below. | |
502 u1(0); | |
503 | |
504 // 11. file_names (sequence of file entries) | |
505 String& uri = String::Handle(zone_); | |
506 for (intptr_t i = 0; i < scripts_.length(); i++) { | |
507 const Script& script = *(scripts_[i]); | |
508 uri ^= script.url(); | |
509 Print(".string \"%s\"\n", uri.ToCString()); | |
510 uleb128(0); // Include directory index. | |
511 uleb128(0); // File modification time. | |
512 uleb128(0); // File length. | |
513 } | |
514 u1(0); // End of file names. | |
515 | |
516 Print(".Llineheader_end:\n"); | |
517 | |
518 // 6.2.5 The Line Number Program | |
519 | |
520 intptr_t previous_file = 1; | |
521 intptr_t previous_line = 1; | |
522 intptr_t previous_code_index = -1; | |
523 intptr_t previous_pc_offset = 0; | |
524 | |
525 Function& root_function = Function::Handle(zone_); | |
526 Script& script = Script::Handle(zone_); | |
527 CodeSourceMap& map = CodeSourceMap::Handle(zone_); | |
528 Array& functions = Array::Handle(zone_); | |
529 GrowableArray<const Function*> function_stack(zone_, 8); | |
530 GrowableArray<TokenPosition> token_positions(zone_, 8); | |
531 | |
532 for (intptr_t i = 0; i < codes_.length(); i++) { | |
533 const Code& code = *(codes_[i]); | |
534 map = code.code_source_map(); | |
535 if (map.IsNull()) { | |
536 continue; | |
537 } | |
538 root_function = code.function(); | |
539 functions = code.inlined_id_to_function(); | |
540 | |
541 NoSafepointScope no_safepoint; | |
542 ReadStream stream(map.Data(), map.Length()); | |
543 | |
544 function_stack.Clear(); | |
545 token_positions.Clear(); | |
546 | |
547 int32_t current_pc_offset = 0; | |
548 function_stack.Add(&root_function); | |
549 token_positions.Add(CodeSourceMapBuilder::kInitialPosition); | |
550 | |
551 while (stream.PendingBytes() > 0) { | |
552 uint8_t opcode = stream.Read<uint8_t>(); | |
553 switch (opcode) { | |
554 case CodeSourceMapBuilder::kChangePosition: { | |
555 int32_t position = stream.Read<int32_t>(); | |
556 token_positions[token_positions.length() - 1] = | |
557 TokenPosition(position); | |
558 break; | |
559 } | |
560 case CodeSourceMapBuilder::kAdvancePC: { | |
561 int32_t delta = stream.Read<int32_t>(); | |
562 current_pc_offset += delta; | |
563 | |
564 const Function& function = *(function_stack.Last()); | |
565 script = function.script(); | |
566 intptr_t file = LookupScript(script); | |
567 | |
568 // 1. Update LNP file. | |
569 if (file != previous_file) { | |
570 u1(DW_LNS_set_file); | |
571 uleb128(file); | |
572 previous_file = file; | |
573 } | |
574 | |
575 // 2. Update LNP line. | |
576 TokenPosition pos = token_positions.Last(); | |
577 intptr_t line = pos.value(); | |
578 if (line != previous_line) { | |
579 u1(DW_LNS_advance_line); | |
580 sleb128(line - previous_line); | |
581 previous_line = line; | |
582 } | |
583 | |
584 // 3. Update LNP pc. | |
585 if (previous_code_index == -1) { | |
586 // This variant is relocatable. | |
587 u1(0); // This is an extended opcode | |
588 u1(1 + sizeof(void*)); // that is 5 or 9 bytes long | |
589 u1(DW_LNE_set_address); | |
590 Print(FORM_ADDR " .Lcode%" Pd " + %" Pd "\n", i, current_pc_offset); | |
591 } else { | |
592 u1(DW_LNS_advance_pc); | |
593 Print(".uleb128 .Lcode%" Pd " - .Lcode%" Pd " + %" Pd "\n", i, | |
594 previous_code_index, current_pc_offset - previous_pc_offset); | |
595 } | |
596 previous_code_index = i; | |
597 previous_pc_offset = current_pc_offset; | |
598 | |
599 // 4. Emit LNP row. | |
600 u1(DW_LNS_copy); | |
601 | |
602 break; | |
603 } | |
604 case CodeSourceMapBuilder::kPushFunction: { | |
605 int32_t func_index = stream.Read<int32_t>(); | |
606 const Function& child_func = Function::Handle( | |
607 zone_, Function::RawCast(functions.At(func_index))); | |
608 function_stack.Add(&child_func); | |
609 token_positions.Add(CodeSourceMapBuilder::kInitialPosition); | |
610 break; | |
611 } | |
612 case CodeSourceMapBuilder::kPopFunction: { | |
613 // We never pop the root function. | |
614 ASSERT(function_stack.length() > 1); | |
615 ASSERT(token_positions.length() > 1); | |
616 function_stack.RemoveLast(); | |
617 token_positions.RemoveLast(); | |
618 break; | |
619 } | |
620 default: | |
621 UNREACHABLE(); | |
622 } | |
623 } | |
624 } | |
625 | |
626 // Advance pc to end of the compilation unit. | |
627 intptr_t last_code_index = codes_.length() - 1; | |
628 const Code& last_code = *(codes_[last_code_index]); | |
629 u1(DW_LNS_advance_pc); | |
630 Print(".uleb128 .Lcode%" Pd " - .Lcode%" Pd " + %" Pd "\n", last_code_index, | |
631 previous_code_index, last_code.Size() - previous_pc_offset); | |
632 | |
633 // End of contiguous machine code. | |
634 u1(0); // This is an extended opcode | |
635 u1(1); // that is 1 byte long | |
636 u1(DW_LNE_end_sequence); | |
637 | |
638 Print(".Lline_end:\n"); | |
639 } | |
640 | |
641 #endif // DART_PRECOMPILER | |
642 | |
643 } // namespace dart | |
OLD | NEW |