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

Two way socket communication with lldb #53

Closed
lanza opened this issue Jan 23, 2019 · 5 comments
Closed

Two way socket communication with lldb #53

lanza opened this issue Jan 23, 2019 · 5 comments

Comments

@lanza
Copy link
Contributor

lanza commented Jan 23, 2019

lldb has listeners and event emitters that will let you know when the state changes and events in the debugger. e.g. you can register to listen for StateChanged and check if StateStopped and StopReasonBreakpoint. This will fix the bt bug where nvim-gdb switches files 14 times for all 14 stack frames due to lldb printing out 14 frames and nvim-gdb parsing 14 different cues to switch files.

And obviously this opens up the possibilities for many other improvements once you get that going. (e.g. querying frame var after every stop and updating a side panel with the variable info, thread lists, frame lists, memory views, etc etc etc)

Here's a little example script that demonstrates the APIs:

https://github.com/apple/swift-lldb/blob/stable/examples/python/performance.py

Any interest on this idea?

@sakhnik
Copy link
Owner

sakhnik commented Jan 23, 2019

Sure, I'd be glad to see this implemented. Would it work for stack frame navigation (up, down) too? These also require jumps in the source code window without actually changing the debugger state.

@sakhnik
Copy link
Owner

sakhnik commented Feb 2, 2019

I'm going to implement a way to execute commands via the side channel (see gdb.customCommand in the branch eval).
User autocommands can be used to notify about the debugger backend state.

@sakhnik
Copy link
Owner

sakhnik commented Feb 3, 2019

@lanza, could you please check this out?
asciicast
I think the idea can be taken even further. The plugin could provide a function to open a window that would "watch" an expression.

@sakhnik sakhnik closed this as completed in 54aa577 Feb 3, 2019
@lanza
Copy link
Contributor Author

lanza commented Feb 4, 2019

So this is a good implementation and idea, but it's not the same as I was talking about in this issue.

The patch you just landed adds the ability to call HandleCommand over a socket interface. So it lets you hide NvimGDB's HandleCommand usage. HandleCommand is the exact same function that is called when you submit something on lldb's command line interface.

So from here on out you should be able to map, for example, GdbBreakpointToggle to lua gdb.customCommand('rb file:line') instead of simply sending it to the terminal buffer in neovim. This could let you hide nvim-gdb's implementation from the user.

This issue was about a different topic, though. lldb_commands.py currently listens to the lua client for requests info-breakpoints and handle-command with the server function. But you can also setup another thread to listen to events from lldb itself and then forward that information to the lua client. This way nvim-gdb can be told when lldb stops at a breakpoint instead of scraping the stdout of the terminal buffer for the frame info.

A clear example of this API usage is at https://reviews.llvm.org/source/lldb/browse/lldb/trunk/examples/python/performance.py. You can walk through this script in PDB to observe what it does. I also just pushed a WIP commit (more of a demo of the idea) to lanza@c22f74f.

@sakhnik sakhnik reopened this Feb 4, 2019
@sakhnik
Copy link
Owner

sakhnik commented Feb 4, 2019

Right, I ignored the first part intentionally. Currently, the debugger state is (tried to be) recognized by parsing the interpreter output. That's a little bit unreliable, but it works quite well for both GDB and PDB. I'd like to keep the implementation unified. But probably, I should agree with you that since LLDB offers a good API, we could harness it through Python without even parsing the output.

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

2 participants