Skip to content
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

ENH: Add LLDB pretty printers for a few SIMPLNX classes. #1178

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

imikejackson
Copy link
Contributor

  • More to come later

There is a bit of setup that one must do in order to get LLDB to use these pretty
printers. Namely create a file called .lldbinit at the top level of your home
directory and put the following code in it:

command script import /Users/${USER}/Workspace1/simplnx/scripts/lldb_pretty_printers/data_path_pretty_printer.py

command script import /Users/${USER}/Workspace1/simplnx/scripts/lldb_pretty_printers/nx_core_array_pretty_printer.py

Where you will need to adjust the path to the actual python files based on how you have your environment setup.

* More to come later

There is a bit of setup that one must do in order to get LLDB to use these pretty
   printers. Namely create a file called `.lldbinit` at the top level of your home
   directory and put the following code in it:

```
command script import /Users/${USER}/Workspace1/simplnx/scripts/lldb_pretty_printers/data_path_pretty_printer.py

command script import /Users/${USER}/Workspace1/simplnx/scripts/lldb_pretty_printers/nx_core_array_pretty_printer.py
```

Where you will need to adjust the path to the actual python files based on how you have your environment setup.

Signed-off-by: Michael Jackson <[email protected]>
Copy link
Collaborator

@JDuffeyBQ JDuffeyBQ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could combine all pretty printers into one package so that you only have one import to do for lldb. It would also let use share utility code between printers.

"""

# 1) Retrieve the m_Array child.
std_array_elements = valobj.GetChildMemberWithName("m_Array").GetChildMemberWithName("__elems_")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This uses the libc++ implementation which means it won't work with libstdc++ which is typical when using clang and lldb on linux.

# Use LLDB's synthetic children for std::vector to retrieve each element.
count = path_valobj.GetNumChildren()
elements = []
for i in range(count):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked at the documentation and fortunately lldb.SBValue has __iter__ so you can do for element in path_valobj.

type summary add -x 'nx::core::Array<.*>' -F nx_core_array_pretty_printer.array_summary
"""
debugger.HandleCommand(
'type summary add -F nx_core_array_pretty_printer.array_summary "nx::core::Array<*,*>"'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'type summary add -F nx_core_array_pretty_printer.array_summary "nx::core::Array<*,*>"'
'type summary add -F nx_core_array_pretty_printer.array_summary -x "nx::core::Array<.*,.*>"'

The -x is what makes the string be interpreted as a regex so it's needed here but not on the others.

We'll display the contents of m_Path (std::vector<std::string>)
as a list of unquoted string values.
"""
path_valobj = valobj.GetChildMemberWithName('m_Path')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might consider a different approach since m_Path is a private variable and an implementation detail so if it changes then this breaks. It is possible to call expressions in lldb like so: valobj.EvaluateExpression('toString()'). I think it's worth looking into at least.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants