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 2 commits 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.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What is the other option?

@imikejackson imikejackson force-pushed the topic/lldb_pretty_printers branch from 2d091c7 to d85b01a Compare February 5, 2025 17:50
@imikejackson imikejackson force-pushed the topic/lldb_pretty_printers branch 2 times, most recently from e7047ca to 6a3aa3e Compare February 19, 2025 14:18
* 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 <mike.jackson@bluequartz.net>
@imikejackson imikejackson force-pushed the topic/lldb_pretty_printers branch from 6a3aa3e to 2a519d1 Compare February 19, 2025 14:33
@JDuffeyBQ
Copy link
Collaborator

I have this script for testing:

nxprinter.py

import lldb

def data_path_summary(valobj: lldb.SBValue, internal_dict: dict) -> str:
  path_valobj: lldb.SBValue = valobj.GetChildMemberWithName('m_Path')

  elements = []
  element: lldb.SBValue
  for element in path_valobj:
    str_val: str = element.GetSummary()
    if str_val is None:
      str_val = '<NULL>'
    else:
      if len(str_val) >= 2 and str_val.startswith('"') and str_val.endswith('"'):
        str_val = str_val[1:-1]
    elements.append(str_val)

  return f"\"{'/'.join(elements)}\""

def array_summary(valobj: lldb.SBValue, internal_dict: dict) -> str:
  array_valobj: lldb.SBValue = valobj.GetChildMemberWithName('m_Array')

  # should "_M_elems" for libstdc++ and "__elems" for libc++
  std_array_elements: lldb.SBValue = array_valobj.child[0]

  if std_array_elements is None:
    return '<unavailable>'

  elements = []
  element: lldb.SBValue
  for element in std_array_elements:
    elem_value = element.GetValue()
    if elem_value is None:
      elem_value = element.GetSummary()
    if elem_value is None:
      elem_value = '<unavailable>'
    elements.append(elem_value)

  return f"({', '.join(elements)})"


def add_type_summary(debugger: lldb.SBDebugger, func_name: str, type_name: str, type_name_is_regex: bool = False) -> None:
  regex_flag = '-x' if type_name_is_regex else ''
  debugger.HandleCommand(
    f'type summary add -F nxprinter.{func_name} {regex_flag} "{type_name}"'
  )

def __lldb_init_module(debugger: lldb.SBDebugger, internal_dict: dict):
  add_type_summary(debugger, 'data_path_summary', 'nx::core::DataPath')
  add_type_summary(debugger, 'array_summary', 'nx::core::Array<.*,.*>', type_name_is_regex=True)

Signed-off-by: Michael Jackson <mike.jackson@bluequartz.net>
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