-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[lldb/docs] Fix/improve the gdb command map for dynamic types #138538
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
The setting and option value names were wrong. I'm assuming this changed over time, but I haven't tried to figure out when.
@llvm/pr-subscribers-lldb Author: Pavel Labath (labath) ChangesThe setting and option value names were wrong. I'm assuming this changed over time, but I haven't tried to figure out when. Full diff: https://github.com/llvm/llvm-project/pull/138538.diff 1 Files Affected:
diff --git a/lldb/docs/use/map.rst b/lldb/docs/use/map.rst
index ed285b2d1f6e9..c648b212006e0 100644
--- a/lldb/docs/use/map.rst
+++ b/lldb/docs/use/map.rst
@@ -800,16 +800,24 @@ Print the dynamic type of the result of an expression
(gdb) p someCPPObjectPtrOrReference
(Only works for C++ objects)
+LLDB does this automatically if determining the dynamic type does not require
+running the target (in C++, running the target is never needed). This default is
+controlled by the `target.prefer-dynamic-value` setting. If that is disabled, it
+can be re-enabled on a per-command basis:
+
.. code-block:: shell
- (lldb) expr -d 1 -- [SomeClass returnAnObject]
- (lldb) expr -d 1 -- someCPPObjectPtrOrReference
+ (lldb) settings set target.prefer-dynamic-value no-dynamic-values
+ (lldb) frame variable -d no-run-target someCPPObjectPtrOrReference
+ (lldb) expr -d no-run-target -- someCPPObjectPtr
-or set dynamic type printing to be the default:
+Note that printing of the dynamic type of references is not possible with the
+`expr` command. The workaround is to take the address of the reference and
+instruct lldb to print the children of the resulting pointer.
.. code-block:: shell
- (lldb) settings set target.prefer-dynamic run-target
+ (lldb) expr -P1 -d no-run-target -- &someCPPObjectReference
Call a function so you can stop at a breakpoint in it
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
Note that printing of the dynamic type of references is not possible with the | ||
`expr` command. The workaround is to take the address of the reference and | ||
instruct lldb to print the children of the resulting pointer. |
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 spent some time trying to make this work, but I came to the conclusion that this would require a relatively big change in how the expression evaluator works. Because we're creating persistent copies of the expression result, it's not just a matter of getting something to recognise the dynamic type of the result -- we would actually need to determine the dynamic type of the object before we create the copy (so that we copy the entire object) -- and then I guess somehow reset the original (non-dynamic) ValueObject to point to the subobject of the result. And that might be too much work to put on the shoulders of the "use-dynamic" setting?
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.
(If you're wondering why we're making a copy of a reference -- but not of a pointer -- I suspect that's because in the expression evaluator we do not differentiate between an object and a reference to it. I suppose we could do it, and then somehow treat references as pointers, but I don't exactly know what would that entail.)
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.
Makes sense to me
…38538) The setting and option value names were wrong. I'm assuming this changed over time, but I haven't tried to figure out when.
The setting and option value names were wrong. I'm assuming this changed over time, but I haven't tried to figure out when.