|
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,14 +697,22 @@ 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) { |
| 700 | +static llvm::json::Value CreateSource(lldb::SBFrame &frame, |
| 701 | + llvm::StringRef frame_name) { |
702 | 702 | auto line_entry = frame.GetLineEntry(); |
703 | 703 | // A line entry of 0 indicates the line is compiler generated i.e. no source |
704 | 704 | // file is associated with the frame. |
705 | 705 | if (line_entry.GetFileSpec().IsValid() && line_entry.GetLine() != 0) |
706 | 706 | return CreateSource(line_entry); |
707 | 707 |
|
708 | | - return {}; |
| 708 | + llvm::json::Object source; |
| 709 | + EmplaceSafeString(source, "name", frame_name); |
| 710 | + source.try_emplace("sourceReference", MakeDAPFrameID(frame)); |
| 711 | + // If we don't have a filespec then we don't have the original source. Mark |
| 712 | + // the source as deemphasized since users will only be able to view assembly |
| 713 | + // for these frames. |
| 714 | + EmplaceSafeString(source, "presentationHint", "deemphasize"); |
| 715 | + return std::move(source); |
709 | 716 | } |
710 | 717 |
|
711 | 718 | // "StackFrame": { |
@@ -799,21 +806,22 @@ llvm::json::Value CreateStackFrame(lldb::SBFrame &frame, |
799 | 806 |
|
800 | 807 | EmplaceSafeString(object, "name", frame_name); |
801 | 808 |
|
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); |
| 809 | + object.try_emplace("source", CreateSource(frame, frame_name)); |
| 810 | + auto line_entry = frame.GetLineEntry(); |
| 811 | + if (line_entry.IsValid() && |
| 812 | + (line_entry.GetLine() != 0 || |
| 813 | + line_entry.GetLine() != LLDB_INVALID_LINE_NUMBER)) { |
| 814 | + object.try_emplace("line", line_entry.GetLine()); |
812 | 815 | auto column = line_entry.GetColumn(); |
813 | 816 | object.try_emplace("column", column); |
814 | 817 | } else { |
815 | | - object.try_emplace("line", 0); |
816 | | - object.try_emplace("column", 0); |
| 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 | + // lines are base-1 indexed |
| 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