OLD | NEW |
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/debugger.h" | 5 #include "vm/debugger.h" |
6 | 6 |
7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
8 | 8 |
9 #include "vm/code_generator.h" | 9 #include "vm/code_generator.h" |
10 #include "vm/code_patcher.h" | 10 #include "vm/code_patcher.h" |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 // Compute token_pos_ and pc_desc_index_. | 357 // Compute token_pos_ and pc_desc_index_. |
358 intptr_t ActivationFrame::TokenPos() { | 358 intptr_t ActivationFrame::TokenPos() { |
359 if (token_pos_ < 0) { | 359 if (token_pos_ < 0) { |
360 token_pos_ = Scanner::kNoSourcePos; | 360 token_pos_ = Scanner::kNoSourcePos; |
361 GetPcDescriptors(); | 361 GetPcDescriptors(); |
362 PcDescriptors::Iterator iter(pc_desc_, RawPcDescriptors::kAnyKind); | 362 PcDescriptors::Iterator iter(pc_desc_, RawPcDescriptors::kAnyKind); |
363 while (iter.HasNext()) { | 363 while (iter.HasNext()) { |
364 const RawPcDescriptors::PcDescriptorRec& rec = iter.Next(); | 364 const RawPcDescriptors::PcDescriptorRec& rec = iter.Next(); |
365 if (rec.pc == pc_) { | 365 if (rec.pc == pc_) { |
366 desc_rec_ = &rec; | 366 desc_rec_ = &rec; |
367 token_pos_ = rec.token_pos; | 367 token_pos_ = rec.token_pos(); |
368 break; | 368 break; |
369 } | 369 } |
370 } | 370 } |
371 } | 371 } |
372 return token_pos_; | 372 return token_pos_; |
373 } | 373 } |
374 | 374 |
375 | 375 |
376 intptr_t ActivationFrame::TryIndex() { | 376 intptr_t ActivationFrame::TryIndex() { |
377 if (desc_rec_ == NULL) { | 377 if (desc_rec_ == NULL) { |
378 return -1; | 378 return -1; |
379 } else { | 379 } else { |
380 return desc_rec_->try_index; | 380 return desc_rec_->try_index(); |
381 } | 381 } |
382 } | 382 } |
383 | 383 |
384 | 384 |
385 intptr_t ActivationFrame::LineNumber() { | 385 intptr_t ActivationFrame::LineNumber() { |
386 // Compute line number lazily since it causes scanning of the script. | 386 // Compute line number lazily since it causes scanning of the script. |
387 if ((line_number_ < 0) && (TokenPos() >= 0)) { | 387 if ((line_number_ < 0) && (TokenPos() >= 0)) { |
388 const Script& script = Script::Handle(SourceScript()); | 388 const Script& script = Script::Handle(SourceScript()); |
389 script.GetTokenLocation(TokenPos(), &line_number_, NULL); | 389 script.GetTokenLocation(TokenPos(), &line_number_, NULL); |
390 } | 390 } |
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
921 } | 921 } |
922 | 922 |
923 | 923 |
924 const uint8_t kSafepointKind = | 924 const uint8_t kSafepointKind = |
925 RawPcDescriptors::kIcCall | RawPcDescriptors::kOptStaticCall | | 925 RawPcDescriptors::kIcCall | RawPcDescriptors::kOptStaticCall | |
926 RawPcDescriptors::kUnoptStaticCall | RawPcDescriptors::kClosureCall | | 926 RawPcDescriptors::kUnoptStaticCall | RawPcDescriptors::kClosureCall | |
927 RawPcDescriptors::kRuntimeCall; | 927 RawPcDescriptors::kRuntimeCall; |
928 | 928 |
929 | 929 |
930 static bool HasTokenPos(const RawPcDescriptors::PcDescriptorRec& rec) { | 930 static bool HasTokenPos(const RawPcDescriptors::PcDescriptorRec& rec) { |
931 return rec.token_pos != Scanner::kNoSourcePos; | 931 return rec.token_pos() != Scanner::kNoSourcePos; |
932 } | 932 } |
933 | 933 |
934 | 934 |
935 CodeBreakpoint::CodeBreakpoint(const Code& code, | 935 CodeBreakpoint::CodeBreakpoint(const Code& code, |
936 const RawPcDescriptors::PcDescriptorRec& rec) | 936 const RawPcDescriptors::PcDescriptorRec& rec) |
937 : code_(code.raw()), | 937 : code_(code.raw()), |
938 token_pos_(rec.token_pos), | 938 token_pos_(rec.token_pos()), |
939 pc_(rec.pc), | 939 pc_(rec.pc), |
940 line_number_(-1), | 940 line_number_(-1), |
941 is_enabled_(false), | 941 is_enabled_(false), |
942 src_bpt_(NULL), | 942 src_bpt_(NULL), |
943 next_(NULL), | 943 next_(NULL), |
944 breakpoint_kind_(rec.kind()), | 944 breakpoint_kind_(rec.kind()), |
945 saved_value_(0) { | 945 saved_value_(0) { |
946 ASSERT(!code.IsNull()); | 946 ASSERT(!code.IsNull()); |
947 ASSERT(token_pos_ > 0); | 947 ASSERT(token_pos_ > 0); |
948 ASSERT(pc_ != 0); | 948 ASSERT(pc_ != 0); |
(...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1545 PcDescriptors& desc = PcDescriptors::Handle(code.pc_descriptors()); | 1545 PcDescriptors& desc = PcDescriptors::Handle(code.pc_descriptors()); |
1546 intptr_t best_fit_pos = INT_MAX; | 1546 intptr_t best_fit_pos = INT_MAX; |
1547 const RawPcDescriptors::PcDescriptorRec* best_fit_rec = NULL; | 1547 const RawPcDescriptors::PcDescriptorRec* best_fit_rec = NULL; |
1548 uword lowest_pc = kUwordMax; | 1548 uword lowest_pc = kUwordMax; |
1549 const RawPcDescriptors::PcDescriptorRec* lowest_pc_rec = NULL; | 1549 const RawPcDescriptors::PcDescriptorRec* lowest_pc_rec = NULL; |
1550 | 1550 |
1551 const RawPcDescriptors::PcDescriptorRec* rec = NULL; | 1551 const RawPcDescriptors::PcDescriptorRec* rec = NULL; |
1552 PcDescriptors::Iterator iter(desc, kSafepointKind); | 1552 PcDescriptors::Iterator iter(desc, kSafepointKind); |
1553 while (iter.HasNext()) { | 1553 while (iter.HasNext()) { |
1554 rec = &iter.Next(); | 1554 rec = &iter.Next(); |
1555 intptr_t desc_token_pos = rec->token_pos; | 1555 intptr_t desc_token_pos = rec->token_pos(); |
1556 ASSERT(desc_token_pos >= 0); | 1556 ASSERT(desc_token_pos >= 0); |
1557 if (HasTokenPos(*rec)) { | 1557 if (HasTokenPos(*rec)) { |
1558 if ((desc_token_pos < requested_token_pos) || | 1558 if ((desc_token_pos < requested_token_pos) || |
1559 (desc_token_pos > last_token_pos)) { | 1559 (desc_token_pos > last_token_pos)) { |
1560 // This descriptor is outside the desired token range. | 1560 // This descriptor is outside the desired token range. |
1561 continue; | 1561 continue; |
1562 } | 1562 } |
1563 if (desc_token_pos < best_fit_pos) { | 1563 if (desc_token_pos < best_fit_pos) { |
1564 // So far, this descriptor has the lowest token position after | 1564 // So far, this descriptor has the lowest token position after |
1565 // the first acceptable token position. | 1565 // the first acceptable token position. |
1566 best_fit_pos = desc_token_pos; | 1566 best_fit_pos = desc_token_pos; |
1567 best_fit_rec = rec; | 1567 best_fit_rec = rec; |
1568 } | 1568 } |
1569 if (rec->pc < lowest_pc) { | 1569 if (rec->pc < lowest_pc) { |
1570 // This descriptor so far has the lowest code address. | 1570 // This descriptor so far has the lowest code address. |
1571 lowest_pc = rec->pc; | 1571 lowest_pc = rec->pc; |
1572 lowest_pc_rec = rec; | 1572 lowest_pc_rec = rec; |
1573 } | 1573 } |
1574 } | 1574 } |
1575 } | 1575 } |
1576 if (lowest_pc_rec != NULL) { | 1576 if (lowest_pc_rec != NULL) { |
1577 // We found the pc descriptor that has the lowest execution address. | 1577 // We found the pc descriptor that has the lowest execution address. |
1578 // This is the first possible breakpoint after the requested token | 1578 // This is the first possible breakpoint after the requested token |
1579 // position. We use this instead of the nearest PC descriptor | 1579 // position. We use this instead of the nearest PC descriptor |
1580 // measured in token index distance. | 1580 // measured in token index distance. |
1581 best_fit_rec = lowest_pc_rec; | 1581 best_fit_rec = lowest_pc_rec; |
1582 } | 1582 } |
1583 if (best_fit_rec != NULL) { | 1583 if (best_fit_rec != NULL) { |
1584 return best_fit_rec->token_pos; | 1584 return best_fit_rec->token_pos(); |
1585 } | 1585 } |
1586 // We didn't find a safe point in the given token range. Try and find | 1586 // We didn't find a safe point in the given token range. Try and find |
1587 // a safe point in the remaining source code of the function. | 1587 // a safe point in the remaining source code of the function. |
1588 if (last_token_pos < func.end_token_pos()) { | 1588 if (last_token_pos < func.end_token_pos()) { |
1589 return ResolveBreakpointPos(func, last_token_pos, func.end_token_pos()); | 1589 return ResolveBreakpointPos(func, last_token_pos, func.end_token_pos()); |
1590 } | 1590 } |
1591 return -1; | 1591 return -1; |
1592 } | 1592 } |
1593 | 1593 |
1594 | 1594 |
1595 void Debugger::MakeCodeBreakpointAt(const Function& func, | 1595 void Debugger::MakeCodeBreakpointAt(const Function& func, |
1596 SourceBreakpoint* bpt) { | 1596 SourceBreakpoint* bpt) { |
1597 ASSERT((bpt != NULL) && bpt->IsResolved()); | 1597 ASSERT((bpt != NULL) && bpt->IsResolved()); |
1598 ASSERT(!func.HasOptimizedCode()); | 1598 ASSERT(!func.HasOptimizedCode()); |
1599 Code& code = Code::Handle(func.unoptimized_code()); | 1599 Code& code = Code::Handle(func.unoptimized_code()); |
1600 ASSERT(!code.IsNull()); | 1600 ASSERT(!code.IsNull()); |
1601 PcDescriptors& desc = PcDescriptors::Handle(code.pc_descriptors()); | 1601 PcDescriptors& desc = PcDescriptors::Handle(code.pc_descriptors()); |
1602 uword lowest_pc = kUwordMax; | 1602 uword lowest_pc = kUwordMax; |
1603 // Find the safe point with the lowest compiled code address | 1603 // Find the safe point with the lowest compiled code address |
1604 // that maps to the token position of the source breakpoint. | 1604 // that maps to the token position of the source breakpoint. |
1605 PcDescriptors::Iterator iter(desc, kSafepointKind); | 1605 PcDescriptors::Iterator iter(desc, kSafepointKind); |
1606 const RawPcDescriptors::PcDescriptorRec* lowest_rec = NULL; | 1606 const RawPcDescriptors::PcDescriptorRec* lowest_rec = NULL; |
1607 while (iter.HasNext()) { | 1607 while (iter.HasNext()) { |
1608 const RawPcDescriptors::PcDescriptorRec& rec = iter.Next(); | 1608 const RawPcDescriptors::PcDescriptorRec& rec = iter.Next(); |
1609 intptr_t desc_token_pos = rec.token_pos; | 1609 intptr_t desc_token_pos = rec.token_pos(); |
1610 if ((desc_token_pos == bpt->token_pos_) && HasTokenPos(rec)) { | 1610 if ((desc_token_pos == bpt->token_pos_) && HasTokenPos(rec)) { |
1611 if (rec.pc < lowest_pc) { | 1611 if (rec.pc < lowest_pc) { |
1612 lowest_pc = rec.pc; | 1612 lowest_pc = rec.pc; |
1613 lowest_rec = &rec; | 1613 lowest_rec = &rec; |
1614 } | 1614 } |
1615 } | 1615 } |
1616 } | 1616 } |
1617 if (lowest_rec == NULL) { | 1617 if (lowest_rec == NULL) { |
1618 return; | 1618 return; |
1619 } | 1619 } |
(...skipping 955 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2575 } | 2575 } |
2576 | 2576 |
2577 | 2577 |
2578 void Debugger::RegisterCodeBreakpoint(CodeBreakpoint* bpt) { | 2578 void Debugger::RegisterCodeBreakpoint(CodeBreakpoint* bpt) { |
2579 ASSERT(bpt->next() == NULL); | 2579 ASSERT(bpt->next() == NULL); |
2580 bpt->set_next(code_breakpoints_); | 2580 bpt->set_next(code_breakpoints_); |
2581 code_breakpoints_ = bpt; | 2581 code_breakpoints_ = bpt; |
2582 } | 2582 } |
2583 | 2583 |
2584 } // namespace dart | 2584 } // namespace dart |
OLD | NEW |