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

Added test locals printing command to GDB #28

Merged
merged 4 commits into from
Jan 12, 2024
Merged

Added test locals printing command to GDB #28

merged 4 commits into from
Jan 12, 2024

Conversation

khlevin
Copy link
Contributor

@khlevin khlevin commented Jan 9, 2024

Added experimental locals printing command to GDB. Command "print-test [recursion-depth]" currently prints a dictionary of found local variables mapped to memory locations, and JSON list of these variables, with fields "name", "type", "value"

Copy link
Collaborator

@nicovank nicovank left a comment

Choose a reason for hiding this comment

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

Delete test/a.out, maybe run black formatter, and LGTM!

Tested with file:

#include <iostream>

struct P {
    int b;
};

struct Q {
    int a;
    P* p;
    P q;
};

struct C {
    C* c;
};

int main() {
    Q q;
    q.a = 1;
    q.p = new P();
    q.p->b = 2;
    q.q.b = 3;

    int i = 0;

    C a;
    C b;
    a.c = &b;
    b.c = &a;

    std::cout << *static_cast<char*>(nullptr) << std::endl;
}

PS: Instead of a max-recursion parameter, maybe we could keep a list of already printed/visited variable within a certain scope, and just stop when visiting again?

def __init__(self):
gdb.Command.__init__(self, "wzd", gdb.COMMAND_DATA, gdb.COMPLETE_SYMBOL, True)

def invoke(self, arg, from_tty):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems like arg contains the entire string after the command, we should be able to parse options this way. (I like argparse personally).

We could use this to add timeout, llm, and other options, provided LLDB has similar functionality.

src/chatdbg/chatdbg_gdb.py Outdated Show resolved Hide resolved
addresses = {}
for symbol in block:
if symbol.is_argument or symbol.is_variable:
variable = {} # Create python dictionary for each variable
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
variable = {} # Create python dictionary for each variable

src/chatdbg/chatdbg_gdb.py Outdated Show resolved Hide resolved
khlevin and others added 3 commits January 12, 2024 13:46
Removed test field

Co-authored-by: Nicolas van Kempen <[email protected]>
Updated command name

Co-authored-by: Nicolas van Kempen <[email protected]>
Removed self from super() args
@khlevin khlevin merged commit 8400ba2 into main Jan 12, 2024
2 checks passed
@khlevin khlevin deleted the print-test branch January 16, 2024 18:40
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