|
17 | 17 | #include "Protocol/ProtocolBase.h" |
18 | 18 | #include "Protocol/ProtocolRequests.h" |
19 | 19 | #include "Protocol/ProtocolTypes.h" |
| 20 | +#include "ProtocolUtils.h" |
20 | 21 | #include "Transport.h" |
21 | 22 | #include "lldb/API/SBBreakpoint.h" |
22 | 23 | #include "lldb/API/SBCommandInterpreter.h" |
@@ -511,22 +512,24 @@ DAP::SendFormattedOutput(OutputType o, const char *format, ...) { |
511 | 512 | } |
512 | 513 |
|
513 | 514 | int32_t DAP::CreateSourceReference(lldb::addr_t address) { |
514 | | - auto iter = llvm::find(source_references, address); |
515 | | - if (iter != source_references.end()) |
516 | | - return std::distance(source_references.begin(), iter) + 1; |
| 515 | + std::lock_guard<std::mutex> guard(m_source_references_mutex); |
| 516 | + auto iter = llvm::find(m_source_references, address); |
| 517 | + if (iter != m_source_references.end()) |
| 518 | + return std::distance(m_source_references.begin(), iter) + 1; |
517 | 519 |
|
518 | | - source_references.emplace_back(address); |
519 | | - return static_cast<int32_t>(source_references.size()); |
| 520 | + m_source_references.emplace_back(address); |
| 521 | + return static_cast<int32_t>(m_source_references.size()); |
520 | 522 | } |
521 | 523 |
|
522 | 524 | std::optional<lldb::addr_t> DAP::GetSourceReferenceAddress(int32_t reference) { |
| 525 | + std::lock_guard<std::mutex> guard(m_source_references_mutex); |
523 | 526 | if (reference <= LLDB_DAP_INVALID_SRC_REF) |
524 | 527 | return std::nullopt; |
525 | 528 |
|
526 | | - if (static_cast<size_t>(reference) > source_references.size()) |
| 529 | + if (static_cast<size_t>(reference) > m_source_references.size()) |
527 | 530 | return std::nullopt; |
528 | 531 |
|
529 | | - return source_references[reference - 1]; |
| 532 | + return m_source_references[reference - 1]; |
530 | 533 | } |
531 | 534 |
|
532 | 535 | ExceptionBreakpoint *DAP::GetExceptionBPFromStopReason(lldb::SBThread &thread) { |
@@ -634,6 +637,22 @@ ReplMode DAP::DetectReplMode(lldb::SBFrame frame, std::string &expression, |
634 | 637 | llvm_unreachable("enum cases exhausted."); |
635 | 638 | } |
636 | 639 |
|
| 640 | +std::optional<protocol::Source> DAP::ResolveSource(lldb::SBAddress address) { |
| 641 | + |
| 642 | + if (DisplayAssemblySource(debugger, address)) { |
| 643 | + auto create_reference = [this](lldb::addr_t addr) { |
| 644 | + return CreateSourceReference(addr); |
| 645 | + }; |
| 646 | + return CreateAssemblySource(target, address, create_reference); |
| 647 | + } |
| 648 | + |
| 649 | + lldb::SBLineEntry line_entry = GetLineEntryForAddress(target, address); |
| 650 | + if (!line_entry.IsValid()) |
| 651 | + return std::nullopt; |
| 652 | + |
| 653 | + return CreateSource(line_entry.GetFileSpec()); |
| 654 | +} |
| 655 | + |
637 | 656 | bool DAP::RunLLDBCommands(llvm::StringRef prefix, |
638 | 657 | llvm::ArrayRef<std::string> commands) { |
639 | 658 | bool required_command_failed = false; |
|
0 commit comments