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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions lldb/docs/use/map.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Comment on lines +814 to +816
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.)


.. 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
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
Loading