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

LLDB Debugging #149

Open
makavity opened this issue Apr 17, 2024 · 0 comments
Open

LLDB Debugging #149

makavity opened this issue Apr 17, 2024 · 0 comments

Comments

@makavity
Copy link

makavity commented Apr 17, 2024

Hello, just done LLDB SyntheticProvider for GenericArray, it is not ideal, but works :)

import lldb

class GenericArraySyntheticProvider:
    def __init__(self, valobj, internal_dict):
        self.valobj = valobj
        self.count = 0
        self.extract_values()

    def extract_values(self):
        self.values = []
        self.types = []
        self.count = 0
        # Assuming data is the root field containing the array structure
        data_valobj = self.valobj.GetChildMemberWithName('data')
        self.traverse(data_valobj)

    def traverse(self, valobj):
        if not valobj.IsValid():
            return
        if valobj.GetNumChildren() == 0:
            return
        for i in range(valobj.GetNumChildren()):
            child = valobj.GetChildAtIndex(i)
            if child.IsValid():
                data_child = child.GetChildMemberWithName('data')
                if data_child.IsValid():
                    self.values.append(data_child.GetData())
                    self.types.append(data_child.GetType())
                    self.count += 1
                self.traverse(child)

    def num_children(self):
        return self.count

    def get_child_index(self, name):
        try:
            return int(name.lstrip('[').rstrip(']'))
        except ValueError:
            return -1

    def get_child_at_index(self, index):
        if index < 0 or index >= self.count:
            return None

        value = self.values[index]
        typo = self.types[index]
        return self.valobj.CreateValueFromData(f"[{index}]", value, typo)

    def update(self):
        # Re-extract values in case the underlying object has changed
        self.extract_values()

    def has_children(self):
        return True

def __lldb_init_module(debugger, internal_dict):
    debugger.HandleCommand(f'type synthetic add -l { __name__ }.GenericArraySyntheticProvider -x "^generic_array::GenericArray<.*>$"')

And command to add it: command script import ~/.lldb/scripts/GenericArray.py in .lldbinit

image
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

No branches or pull requests

1 participant