-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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: disableASLR launch argument not working. #129753
[lldb-dap] Fix: disableASLR launch argument not working. #129753
Conversation
@llvm/pr-subscribers-lldb Author: None (Da-Viper) ChangesFixes #94338 disable_aslr.mp4i used Full diff: https://github.com/llvm/llvm-project/pull/129753.diff 1 Files Affected:
diff --git a/lldb/tools/lldb-dap/Handler/RequestHandler.cpp b/lldb/tools/lldb-dap/Handler/RequestHandler.cpp
index 606ada90ce2e5..f56821ec03e27 100644
--- a/lldb/tools/lldb-dap/Handler/RequestHandler.cpp
+++ b/lldb/tools/lldb-dap/Handler/RequestHandler.cpp
@@ -175,6 +175,9 @@ RequestHandler::LaunchProcess(const llvm::json::Object &request) const {
if (GetBoolean(arguments, "disableASLR", true))
flags |= lldb::eLaunchFlagDisableASLR;
+ else
+ flags &= ~lldb::eLaunchFlagDisableASLR;
+
if (GetBoolean(arguments, "disableSTDIO", false))
flags |= lldb::eLaunchFlagDisableSTDIO;
if (GetBoolean(arguments, "shellExpandArguments", false))
|
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.
I'd like to suggest two improvements:
- Add an overload to
GetBoolean
that returns anstd::optional<bool>
so we know if the value was not set, or explicitly set totrue
orfalse
. - Have a helper that does the same thing for all the flags: set or clear it depending on whether the value was set, or do nothing if it wasn't set.
WDYT?
SetMask(uint32_t &flags, LaunchInfo mask);
ClearMask(uint32_t &flags, LaunchInfo mask);
|
Okay, just to confirm, you're saying that's it's not possible for these values not to be set?
I was thinking something like:
Edit: this could probably be a lambda. |
Yes because lldb has default values for all its settings. using see llvm-project/lldb/source/Target/TargetProperties.td Lines 143 to 145 in a12744f
|
I kind of agree with Jonas' initial remark. Wouldn't it be better to conceptually have something like this:
that way you can let LLDB set the flag value on its own. An interesting case when this might be useful is if one of the initCommands sets the default value for this setting, then you don't want to change this unless the disableASLR field in the debug config is set explicitly |
Alright. One more thing if it is better to return a flag from function or pass a reference. static setLaunchFlag(uint32_t &flags, const llvm::json::Object *obj,
llvm::StringRef key, lldb::LaunchFlags mask,
bool default_value) {
if (HasBoolean(obj, key))
if (GetBoolean(obj, key, default_value))
flags |= mask;
else
flags &= ~mask;
}
setLaunchFlag(flags, arguments, "disableASLR",
lldb::eLaunchFlagDisableASLR, false); vs static uint32_t setLaunchFlag(uint32_t flags, const llvm::json::Object *obj,
llvm::StringRef key, lldb::LaunchFlags mask,
bool default_value) {
if (HasBoolean(obj, key))
if (GetBoolean(obj, key, default_value))
flags |= mask;
else
flags &= ~mask;
return flags;
}
flags = setLaunchFlag(flags, arguments, "disableASLR",
lldb::eLaunchFlagDisableASLR, false);
|
I don't think we need to have both the
to this:
All existing uses of FWIW this applies to all the |
Oh yes, I completely agree with |
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.
requesting changes given the existing discussion
Return a std::optional<bool> from GetBoolean so you can distinguish between the value not being present and it being explicitly set to true or false. All existing uses are replaced by calling `value_or(fail_value`). Motivated by #129753
22aede0
to
2f773de
Compare
Different timezone, updated the commit with the new changes. |
static uint32_t SetLaunchFlag(uint32_t flags, const llvm::json::Object *obj, | ||
llvm::StringRef key, lldb::LaunchFlags mask, | ||
bool default_value) { | ||
if (GetBoolean(obj, key).value_or(default_value)) | ||
flags |= mask; | ||
else | ||
flags &= ~mask; | ||
|
||
return flags; | ||
} |
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 still doesn't distinguish between the value not being set and the value being set to true
or false
. Here's what I was suggesting:
static uint32_t SetLaunchFlag(uint32_t flags, const llvm::json::Object *obj, | |
llvm::StringRef key, lldb::LaunchFlags mask, | |
bool default_value) { | |
if (GetBoolean(obj, key).value_or(default_value)) | |
flags |= mask; | |
else | |
flags &= ~mask; | |
return flags; | |
} | |
static uint32_t SetLaunchFlag(uint32_t flags, const llvm::json::Object *obj, | |
llvm::StringRef key, lldb::LaunchFlags mask) { | |
if (auto b = GetBoolean(obj, key)) { | |
if (*b) | |
flags |= mask; | |
else | |
flags &= ~mask; | |
} | |
return flags; | |
} |
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. Thanks for bearing with me.
Fixes #94338
disable_aslr.mp4
i used
pidof a.out | xargs pmap
to show the memory map of the binary