|
19 | 19 | #include "lldb/API/SBFileSpec.h" |
20 | 20 | #include "lldb/API/SBFrame.h" |
21 | 21 | #include "lldb/API/SBFunction.h" |
| 22 | +#include "lldb/API/SBInstruction.h" |
| 23 | +#include "lldb/API/SBInstructionList.h" |
22 | 24 | #include "lldb/API/SBLineEntry.h" |
23 | 25 | #include "lldb/API/SBModule.h" |
24 | 26 | #include "lldb/API/SBQueue.h" |
@@ -719,8 +721,8 @@ llvm::json::Value CreateSource(llvm::StringRef source_path) { |
719 | 721 | // }, |
720 | 722 | // "required": [ "id", "name", "line", "column" ] |
721 | 723 | // } |
722 | | -llvm::json::Value CreateStackFrame(lldb::SBFrame &frame, |
723 | | - lldb::SBFormat &format) { |
| 724 | +llvm::json::Value CreateStackFrame(lldb::SBFrame &frame, lldb::SBFormat &format, |
| 725 | + lldb::SBTarget &target) { |
724 | 726 | llvm::json::Object object; |
725 | 727 | int64_t frame_id = MakeDAPFrameID(frame); |
726 | 728 | object.try_emplace("id", frame_id); |
@@ -776,10 +778,18 @@ llvm::json::Value CreateStackFrame(lldb::SBFrame &frame, |
776 | 778 |
|
777 | 779 | // Calculate the line of the current PC from the start of the current |
778 | 780 | // symbol. |
779 | | - lldb::addr_t inst_offset = frame.GetPCAddress().GetOffset() - |
780 | | - frame.GetSymbol().GetStartAddress().GetOffset(); |
781 | | - lldb::addr_t inst_line = |
782 | | - inst_offset / (frame.GetThread().GetProcess().GetAddressByteSize() / 2); |
| 781 | + lldb::SBAddress current_address = frame.GetPCAddress(); |
| 782 | + lldb::SBInstructionList inst_list = |
| 783 | + frame.GetSymbol().GetInstructions(target); |
| 784 | + size_t inst_line = 0; |
| 785 | + for (size_t i = 0; i < inst_list.GetSize(); ++i) { |
| 786 | + lldb::SBInstruction inst = inst_list.GetInstructionAtIndex(i); |
| 787 | + if (inst.GetAddress() == current_address) { |
| 788 | + inst_line = i; |
| 789 | + break; |
| 790 | + } |
| 791 | + } |
| 792 | + |
783 | 793 | // Line numbers are 1-based. |
784 | 794 | object.try_emplace("line", inst_line + 1); |
785 | 795 | object.try_emplace("column", 1); |
|
0 commit comments