Browse Source

Add a `StaticVector` pretty-printer for LLDB

pull/7347/head
Gleb Mazovetskiy 2 years ago
parent
commit
81452d870d
  1. 4
      .lldbinit
  2. 17
      tools/lldbutils/README.md
  3. 6
      tools/lldbutils/lldbutils/__init__.py
  4. 32
      tools/lldbutils/lldbutils/pretty_printers/utils/static_vector_pp.py

4
.lldbinit

@ -0,0 +1,4 @@
script topsrcdir = topsrcdir if "topsrcdir" in locals() else os.getcwd()
script sys.path.append(os.path.join(topsrcdir, "tools/lldbutils"))
script import lldbutils
script lldbutils.init()

17
tools/lldbutils/README.md

@ -0,0 +1,17 @@
# lldb debugging enhancements
The code in this directory is imported via `.lldbinit`.
Working directory `.lldbinit` is not loaded by default.
You can add the following to `~/.lldbinit` to load it when launching `lldb` from the command line:
```
settings set target.load-cwd-lldbinit true
```
If you're using VS Code, you can instead add the following to your configuration:
```json
"lldb.launch.initCommands": ["command source ${workspaceFolder}/.lldbinit"]
```

6
tools/lldbutils/lldbutils/__init__.py

@ -0,0 +1,6 @@
import lldb
import lldbutils.pretty_printers.utils.static_vector_pp
def init():
lldbutils.pretty_printers.utils.static_vector_pp.init(lldb.debugger)

32
tools/lldbutils/lldbutils/pretty_printers/utils/static_vector_pp.py

@ -0,0 +1,32 @@
import lldb
class StaticVectorSyntheticChildrenProvider:
def __init__(self, valobj: lldb.SBValue, internal_dict):
self._val: lldb.SBValue = valobj
self._size: lldb.SBValue = self._val.GetChildMemberWithName("size_")
self._element_type: lldb.SBType = self._val.GetType().GetTemplateArgumentType(0)
self._element_size = self._element_type.GetByteSize()
self._data_addr = int(
self._val.GetChildMemberWithName("data_").GetLoadAddress()
)
def num_children(self, max_children):
return self._size.GetValueAsUnsigned(0)
def get_child_index(self, name):
index = int(name)
return index if index < self.num_children() else None
def get_child_at_index(self, index):
return self._val.CreateValueFromAddress(
f"[{index}]",
self._data_addr + self._element_size * index,
self._element_type,
)
def init(debugger: lldb.debugger):
debugger.HandleCommand(
'type synthetic add -x "devilution::StaticVector<" -l lldbutils.pretty_printers.utils.static_vector_pp.StaticVectorSyntheticChildrenProvider'
)
Loading…
Cancel
Save