Skip to content

[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

Merged
merged 1 commit into from
May 6, 2025

Conversation

labath
Copy link
Collaborator

@labath labath commented May 5, 2025

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.
@labath labath requested a review from Michael137 May 5, 2025 15:00
@labath labath requested a review from JDevlieghere as a code owner May 5, 2025 15:00
@llvmbot llvmbot added the lldb label May 5, 2025
@llvmbot
Copy link
Member

llvmbot commented May 5, 2025

@llvm/pr-subscribers-lldb

Author: Pavel Labath (labath)

Changes

The 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:

  • (modified) lldb/docs/use/map.rst (+12-4)
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
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Comment on lines +814 to +816
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.
Copy link
Collaborator Author

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?

Copy link
Collaborator Author

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.)

Copy link
Member

@Michael137 Michael137 left a 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

@labath labath merged commit 6a99d81 into llvm:main May 6, 2025
12 checks passed
@labath labath deleted the dynamic branch May 6, 2025 13:06
GeorgeARM pushed a commit to GeorgeARM/llvm-project that referenced this pull request May 7, 2025
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants