-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[lldb-dap] Fixing a type encoding issue with dap Stopped events. #72292
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
Conversation
@llvm/pr-subscribers-lldb Author: John Harrison (ashgti) ChangesPreviously the type of the breakpoint id in the Stopped event was a uint64_t, however thats the wrong type for a breakpoint id, which can cause encoding issues when internal breakpoints are hit. Full diff: https://github.com/llvm/llvm-project/pull/72292.diff 1 Files Affected:
diff --git a/lldb/tools/lldb-dap/JSONUtils.cpp b/lldb/tools/lldb-dap/JSONUtils.cpp
index 2023291729762f1..2b96c4f21aeb04d 100644
--- a/lldb/tools/lldb-dap/JSONUtils.cpp
+++ b/lldb/tools/lldb-dap/JSONUtils.cpp
@@ -953,9 +953,9 @@ llvm::json::Value CreateThreadStopped(lldb::SBThread &thread,
} else {
body.try_emplace("reason", "breakpoint");
char desc_str[64];
- uint64_t bp_id = thread.GetStopReasonDataAtIndex(0);
- uint64_t bp_loc_id = thread.GetStopReasonDataAtIndex(1);
- snprintf(desc_str, sizeof(desc_str), "breakpoint %" PRIu64 ".%" PRIu64,
+ break_id_t bp_id = thread.GetStopReasonDataAtIndex(0);
+ break_id_t bp_loc_id = thread.GetStopReasonDataAtIndex(1);
+ snprintf(desc_str, sizeof(desc_str), "breakpoint %" PRIo32 ".%" PRIo32,
bp_id, bp_loc_id);
body.try_emplace("hitBreakpointIds",
llvm::json::Array{llvm::json::Value(bp_id)});
|
lldb/tools/lldb-dap/JSONUtils.cpp
Outdated
snprintf(desc_str, sizeof(desc_str), "breakpoint %" PRIu64 ".%" PRIu64, | ||
break_id_t bp_id = thread.GetStopReasonDataAtIndex(0); | ||
break_id_t bp_loc_id = thread.GetStopReasonDataAtIndex(1); | ||
snprintf(desc_str, sizeof(desc_str), "breakpoint %" PRIo32 ".%" PRIo32, |
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.
could you change this to use formatv? This kind of printing hurts my eyes.
Isn't PRIo32 octal?
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.
Switched to llvm::vformat instead.
lldb/tools/lldb-dap/JSONUtils.cpp
Outdated
snprintf(desc_str, sizeof(desc_str), "breakpoint %" PRIu64 ".%" PRIu64, | ||
break_id_t bp_id = thread.GetStopReasonDataAtIndex(0); | ||
break_id_t bp_loc_id = thread.GetStopReasonDataAtIndex(1); | ||
snprintf(desc_str, sizeof(desc_str), "breakpoint %" PRIo32 ".%" PRIo32, |
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.
This is indeed octal which isn't what we want. You need to use PRIi32
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.
Switched to llvm::vformat
.
lldb/tools/lldb-dap/JSONUtils.cpp
Outdated
uint64_t bp_id = thread.GetStopReasonDataAtIndex(0); | ||
uint64_t bp_loc_id = thread.GetStopReasonDataAtIndex(1); | ||
snprintf(desc_str, sizeof(desc_str), "breakpoint %" PRIu64 ".%" PRIu64, | ||
break_id_t bp_id = thread.GetStopReasonDataAtIndex(0); |
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.
This looks like an implicit cast from uint64_t to int32_t, how safe is this?
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.
We have an abstract API to access stop reason data via uint64_t SBThread::GetStopReasonDataAtIndex(...)
which returns a uint64_t
, but the break_id_t
is defined as typedef int32_t break_id_t;
. If we want to show the breakpoint ID correctly as a negative number for internal breakpoints, then this should be ok.
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.
These are implicitly cast here https://github.com/llvm/llvm-project/blob/e823136d43c40b0a9ba6930fd285768f1b46fcb6/lldb/source/API/SBThread.cpp#L251C35-L251C48 to uint64_t, this is converting it back to the internal type. This should be okay.
Previously the type of the breakpoint id in the Stopped event was a uint64_t, however thats the wrong type for a breakpoint id, which can cause encoding issues when internal breakpoints are hit.
LGTM. I didn't mean to accept the patch when it was using |
Previously the type of the breakpoint id in the Stopped event was a uint64_t, however thats the wrong type for a breakpoint id, which can cause encoding issues when internal breakpoints are hit.