-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[lldb-dap] fix wrong assembly line number x64 #136486
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[lldb-dap] fix wrong assembly line number x64 #136486
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-lldb Author: Ely Ronnen (eronnen) ChangesFix wrong assembly line number calculation that assumes the instruction size is Full diff: https://github.com/llvm/llvm-project/pull/136486.diff 3 Files Affected:
diff --git a/lldb/tools/lldb-dap/Handler/StackTraceRequestHandler.cpp b/lldb/tools/lldb-dap/Handler/StackTraceRequestHandler.cpp
index a58e3325af100..5d1d2835b4392 100644
--- a/lldb/tools/lldb-dap/Handler/StackTraceRequestHandler.cpp
+++ b/lldb/tools/lldb-dap/Handler/StackTraceRequestHandler.cpp
@@ -67,7 +67,8 @@ static bool FillStackFrames(DAP &dap, lldb::SBThread &thread,
break;
}
- stack_frames.emplace_back(CreateStackFrame(frame, dap.frame_format));
+ stack_frames.emplace_back(
+ CreateStackFrame(frame, dap.frame_format, dap.target));
}
if (dap.configuration.displayExtendedBacktrace && reached_end_of_stack) {
diff --git a/lldb/tools/lldb-dap/JSONUtils.cpp b/lldb/tools/lldb-dap/JSONUtils.cpp
index 33f10c93d2ada..552fdc9439845 100644
--- a/lldb/tools/lldb-dap/JSONUtils.cpp
+++ b/lldb/tools/lldb-dap/JSONUtils.cpp
@@ -19,6 +19,8 @@
#include "lldb/API/SBFileSpec.h"
#include "lldb/API/SBFrame.h"
#include "lldb/API/SBFunction.h"
+#include "lldb/API/SBInstruction.h"
+#include "lldb/API/SBInstructionList.h"
#include "lldb/API/SBLineEntry.h"
#include "lldb/API/SBModule.h"
#include "lldb/API/SBQueue.h"
@@ -719,8 +721,8 @@ llvm::json::Value CreateSource(llvm::StringRef source_path) {
// },
// "required": [ "id", "name", "line", "column" ]
// }
-llvm::json::Value CreateStackFrame(lldb::SBFrame &frame,
- lldb::SBFormat &format) {
+llvm::json::Value CreateStackFrame(lldb::SBFrame &frame, lldb::SBFormat &format,
+ lldb::SBTarget &target) {
llvm::json::Object object;
int64_t frame_id = MakeDAPFrameID(frame);
object.try_emplace("id", frame_id);
@@ -776,10 +778,18 @@ llvm::json::Value CreateStackFrame(lldb::SBFrame &frame,
// Calculate the line of the current PC from the start of the current
// symbol.
- lldb::addr_t inst_offset = frame.GetPCAddress().GetOffset() -
- frame.GetSymbol().GetStartAddress().GetOffset();
- lldb::addr_t inst_line =
- inst_offset / (frame.GetThread().GetProcess().GetAddressByteSize() / 2);
+ lldb::SBAddress current_address = frame.GetPCAddress();
+ lldb::SBInstructionList inst_list =
+ frame.GetSymbol().GetInstructions(target);
+ size_t inst_line = 0;
+ for (size_t i = 0; i < inst_list.GetSize(); ++i) {
+ lldb::SBInstruction inst = inst_list.GetInstructionAtIndex(i);
+ if (inst.GetAddress() == current_address) {
+ inst_line = i;
+ break;
+ }
+ }
+
// Line numbers are 1-based.
object.try_emplace("line", inst_line + 1);
object.try_emplace("column", 1);
diff --git a/lldb/tools/lldb-dap/JSONUtils.h b/lldb/tools/lldb-dap/JSONUtils.h
index b8c53353bf42d..ffa10743501b8 100644
--- a/lldb/tools/lldb-dap/JSONUtils.h
+++ b/lldb/tools/lldb-dap/JSONUtils.h
@@ -363,11 +363,14 @@ llvm::json::Value CreateSource(llvm::StringRef source_path);
/// The LLDB format to use when populating out the "StackFrame"
/// object.
///
+/// \param[in] target
+/// The LLDB target to use when populating out the "StackFrame"
+/// object.
/// \return
/// A "StackFrame" JSON object with that follows the formal JSON
/// definition outlined by Microsoft.
-llvm::json::Value CreateStackFrame(lldb::SBFrame &frame,
- lldb::SBFormat &format);
+llvm::json::Value CreateStackFrame(lldb::SBFrame &frame, lldb::SBFormat &format,
+ lldb::SBTarget &target);
/// Create a "StackFrame" label object for a LLDB thread.
///
|
0efcbcf
to
9d9ffee
Compare
Edit: improved the patch by using |
✅ With the latest revision this PR passed the C/C++ code formatter. |
3748df8
to
3a0a962
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM but I'd like to have a (x86) test that would have failed without this case.
… sized instructions
3a0a962
to
c002260
Compare
@JDevlieghere added a test that checks that |
c002260
to
9f285f8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
|
||
class TestDAP_stacktrace_x86(lldbdap_testcase.DAPTestCaseBase): | ||
@skipUnlessArch("x86_64") | ||
@skipUnlessPlatform(["linux"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this really limited to linux? It seems like this should work on at least Darwin too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems like it should work, changing
) | ||
|
||
for i in range(2, minimum_assembly_lines): | ||
self.stepIn() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we explicitly step with granularity='instruction'
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be the same because it's a function without debug symbols so each step should execute one assembly instruction
@eronnen Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. How to do this, and the rest of the post-merge process, is covered in detail here. If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
Fix wrong assembly line number calculation that assumes the instruction size is `GetAddressByteSize() / 2` Fixes llvm#136495
Fix wrong assembly line number calculation that assumes the instruction size is `GetAddressByteSize() / 2` Fixes llvm#136495
Fix wrong assembly line number calculation that assumes the instruction size is `GetAddressByteSize() / 2` Fixes llvm#136495
Fix wrong assembly line number calculation that assumes the instruction size is `GetAddressByteSize() / 2` Fixes llvm#136495
Fix wrong assembly line number calculation that assumes the instruction size is `GetAddressByteSize() / 2` Fixes llvm#136495
Fix wrong assembly line number calculation that assumes the instruction size is
GetAddressByteSize() / 2
Fixes #136495