|
41 | 41 | #include "llvm/Support/Compiler.h" |
42 | 42 | #include "llvm/Support/Format.h" |
43 | 43 | #include "llvm/Support/FormatVariadic.h" |
| 44 | +#include "llvm/Support/JSON.h" |
44 | 45 | #include "llvm/Support/Path.h" |
45 | 46 | #include "llvm/Support/ScopedPrinter.h" |
46 | 47 | #include "llvm/Support/raw_ostream.h" |
|
50 | 51 | #include <optional> |
51 | 52 | #include <sstream> |
52 | 53 | #include <string> |
| 54 | +#include <sys/syslimits.h> |
53 | 55 | #include <utility> |
54 | 56 | #include <vector> |
55 | 57 |
|
@@ -697,24 +699,6 @@ llvm::json::Value CreateSource(llvm::StringRef source_path) { |
697 | 699 | return llvm::json::Value(std::move(source)); |
698 | 700 | } |
699 | 701 |
|
700 | | -static llvm::json::Value CreateSource(lldb::SBFrame &frame, |
701 | | - llvm::StringRef frame_name) { |
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 | | - 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); |
716 | | -} |
717 | | - |
718 | 702 | // "StackFrame": { |
719 | 703 | // "type": "object", |
720 | 704 | // "description": "A Stackframe contains the source location.", |
@@ -806,20 +790,38 @@ llvm::json::Value CreateStackFrame(lldb::SBFrame &frame, |
806 | 790 |
|
807 | 791 | EmplaceSafeString(object, "name", frame_name); |
808 | 792 |
|
809 | | - object.try_emplace("source", CreateSource(frame, frame_name)); |
810 | 793 | auto line_entry = frame.GetLineEntry(); |
811 | | - if (line_entry.IsValid() && |
| 794 | + // A line entry of 0 indicates the line is compiler generated i.e. no source |
| 795 | + // file is associated with the frame. |
| 796 | + if (line_entry.GetFileSpec().IsValid() && |
812 | 797 | (line_entry.GetLine() != 0 || |
813 | 798 | line_entry.GetLine() != LLDB_INVALID_LINE_NUMBER)) { |
| 799 | + object.try_emplace("source", CreateSource(line_entry)); |
814 | 800 | object.try_emplace("line", line_entry.GetLine()); |
815 | 801 | auto column = line_entry.GetColumn(); |
816 | 802 | object.try_emplace("column", column); |
817 | | - } else { |
| 803 | + } else if (frame.GetSymbol().IsValid()) { |
| 804 | + // If no source is associated with the frame, use the DAPFrameID to track |
| 805 | + // the 'source' and generate assembly. |
| 806 | + llvm::json::Object source; |
| 807 | + EmplaceSafeString(source, "name", frame_name); |
| 808 | + char buf[PATH_MAX] = {0}; |
| 809 | + size_t size = frame.GetModule().GetFileSpec().GetPath(buf, PATH_MAX); |
| 810 | + EmplaceSafeString(source, "path", |
| 811 | + std::string(buf, size) + '`' + frame_name); |
| 812 | + source.try_emplace("sourceReference", MakeDAPFrameID(frame)); |
| 813 | + // Markthe source as deemphasized since users will only be able to view |
| 814 | + // assembly for these frames. |
| 815 | + EmplaceSafeString(source, "presentationHint", "deemphasize"); |
| 816 | + object.try_emplace("source", std::move(source)); |
| 817 | + |
| 818 | + // Calculate the line of the current PC from the start of the current |
| 819 | + // symbol. |
818 | 820 | lldb::addr_t inst_offset = frame.GetPCAddress().GetOffset() - |
819 | 821 | frame.GetSymbol().GetStartAddress().GetOffset(); |
820 | 822 | lldb::addr_t inst_line = |
821 | 823 | inst_offset / (frame.GetThread().GetProcess().GetAddressByteSize() / 2); |
822 | | - // Line numbers are 1-based. |
| 824 | + // Line numbers are 1-based. |
823 | 825 | object.try_emplace("line", inst_line + 1); |
824 | 826 | object.try_emplace("column", 1); |
825 | 827 | } |
|
0 commit comments