forked from diasurgical/DevilutionX
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a
StaticVector
pretty-printer for LLDB
- Loading branch information
Showing
4 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 changes: 32 additions & 0 deletions
32
tools/lldbutils/lldbutils/pretty_printers/utils/static_vector_pp.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' | ||
) |