|
7 | 7 | //===----------------------------------------------------------------------===// |
8 | 8 |
|
9 | 9 | #include "JSONUtils.h" |
10 | | - |
11 | 10 | #include "BreakpointBase.h" |
12 | 11 | #include "DAP.h" |
13 | 12 | #include "ExceptionBreakpoint.h" |
|
41 | 40 | #include "llvm/Support/Compiler.h" |
42 | 41 | #include "llvm/Support/Format.h" |
43 | 42 | #include "llvm/Support/FormatVariadic.h" |
| 43 | +#include "llvm/Support/JSON.h" |
44 | 44 | #include "llvm/Support/Path.h" |
45 | 45 | #include "llvm/Support/ScopedPrinter.h" |
46 | 46 | #include "llvm/Support/raw_ostream.h" |
47 | 47 | #include <chrono> |
48 | | -#include <climits> |
49 | 48 | #include <cstddef> |
50 | 49 | #include <iomanip> |
51 | 50 | #include <optional> |
@@ -698,16 +697,6 @@ llvm::json::Value CreateSource(llvm::StringRef source_path) { |
698 | 697 | return llvm::json::Value(std::move(source)); |
699 | 698 | } |
700 | 699 |
|
701 | | -static std::optional<llvm::json::Value> CreateSource(lldb::SBFrame &frame) { |
702 | | - auto line_entry = frame.GetLineEntry(); |
703 | | - // A line entry of 0 indicates the line is compiler generated i.e. no source |
704 | | - // file is associated with the frame. |
705 | | - if (line_entry.GetFileSpec().IsValid() && line_entry.GetLine() != 0) |
706 | | - return CreateSource(line_entry); |
707 | | - |
708 | | - return {}; |
709 | | -} |
710 | | - |
711 | 700 | // "StackFrame": { |
712 | 701 | // "type": "object", |
713 | 702 | // "description": "A Stackframe contains the source location.", |
@@ -799,21 +788,40 @@ llvm::json::Value CreateStackFrame(lldb::SBFrame &frame, |
799 | 788 |
|
800 | 789 | EmplaceSafeString(object, "name", frame_name); |
801 | 790 |
|
802 | | - auto source = CreateSource(frame); |
803 | | - |
804 | | - if (source) { |
805 | | - object.try_emplace("source", *source); |
806 | | - auto line_entry = frame.GetLineEntry(); |
807 | | - auto line = line_entry.GetLine(); |
808 | | - if (line && line != LLDB_INVALID_LINE_NUMBER) |
809 | | - object.try_emplace("line", line); |
810 | | - else |
811 | | - object.try_emplace("line", 0); |
| 791 | + auto line_entry = frame.GetLineEntry(); |
| 792 | + // A line entry of 0 indicates the line is compiler generated i.e. no source |
| 793 | + // file is associated with the frame. |
| 794 | + if (line_entry.GetFileSpec().IsValid() && |
| 795 | + (line_entry.GetLine() != 0 || |
| 796 | + line_entry.GetLine() != LLDB_INVALID_LINE_NUMBER)) { |
| 797 | + object.try_emplace("source", CreateSource(line_entry)); |
| 798 | + object.try_emplace("line", line_entry.GetLine()); |
812 | 799 | auto column = line_entry.GetColumn(); |
813 | 800 | object.try_emplace("column", column); |
814 | | - } else { |
815 | | - object.try_emplace("line", 0); |
816 | | - object.try_emplace("column", 0); |
| 801 | + } else if (frame.GetSymbol().IsValid()) { |
| 802 | + // If no source is associated with the frame, use the DAPFrameID to track |
| 803 | + // the 'source' and generate assembly. |
| 804 | + llvm::json::Object source; |
| 805 | + EmplaceSafeString(source, "name", frame_name); |
| 806 | + char buf[PATH_MAX] = {0}; |
| 807 | + size_t size = frame.GetModule().GetFileSpec().GetPath(buf, PATH_MAX); |
| 808 | + EmplaceSafeString(source, "path", |
| 809 | + std::string(buf, size) + '`' + frame_name); |
| 810 | + source.try_emplace("sourceReference", MakeDAPFrameID(frame)); |
| 811 | + // Mark the source as deemphasized since users will only be able to view |
| 812 | + // assembly for these frames. |
| 813 | + EmplaceSafeString(source, "presentationHint", "deemphasize"); |
| 814 | + object.try_emplace("source", std::move(source)); |
| 815 | + |
| 816 | + // Calculate the line of the current PC from the start of the current |
| 817 | + // symbol. |
| 818 | + lldb::addr_t inst_offset = frame.GetPCAddress().GetOffset() - |
| 819 | + frame.GetSymbol().GetStartAddress().GetOffset(); |
| 820 | + lldb::addr_t inst_line = |
| 821 | + inst_offset / (frame.GetThread().GetProcess().GetAddressByteSize() / 2); |
| 822 | + // Line numbers are 1-based. |
| 823 | + object.try_emplace("line", inst_line + 1); |
| 824 | + object.try_emplace("column", 1); |
817 | 825 | } |
818 | 826 |
|
819 | 827 | const auto pc = frame.GetPC(); |
|
0 commit comments