-
Notifications
You must be signed in to change notification settings - Fork 455
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
A new and improved lldb_bson.py #1238
Conversation
Added review requests, but mostly curious to see if this "(only) works on my machine" and what may need to be tweaked to work in different environments/LLDBs. |
Long time GDB user, but I haven't used lldb before. How does one use this script with lldb? |
@kkloberdanz I got it up and running using the VS Code Debugging and CodeLLDB User Manual as reference. @vector-of-bool At the moment there does not seem to be a way to distinguish Can we display integral fields in a manner similar to what is done for the datetime field such that this distinction can be made, e.g. something like the following?
|
Thanks! Would anyone know off hand if there is a way to use this from the lldb CLI? |
I've tweaked the summary strings to show the type info in a similar manner to what is displayed on the Mongo CLI (e.g. @kkloberdanz you should be able to import it with: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fantastic. This seems very helpful for inspecting BSON while debugging.
I did not review the implementation but checked the output by debugging the /bson/iter/init_from_data_at_offset
test, which includes a BSON document with all types.
Here is the launch.json I used:
{
"name": "test-libmongoc",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/cmake-build/src/libmongoc/test-libmongoc",
"args": [
"--no-fork",
"--match",
"/bson/iter/init_from_data_at_offset"
],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"setupCommands": [
{
"text": "command script import ${workspaceFolder}/lldb_bson.py"
}
],
"environment": [],
"externalConsole": false,
"MIMode": "lldb"
}
LGTM with documentation updated.
|
||
debugger.HandleCommand( | ||
'command script add --help \"%s\"' | ||
' -f lldb_bson.bson_as_json_command bson' % |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update the LLDB documentation, since it may no longer be correct.
This PR rewrites the lldb_bson.py Python module for use in the LLDB debugger. The prior version supported simple inspection of BSON data as its equivalent JSON encoding, but this was often cumbersome and difficult to read.
This new module allows traversing and watching document elements (with arbitrary nesting), as well as introspection on element values. In VSCode, this also enables jump-to-memory on individual elements.
The new
lldb_bson.py
is large, and shares very little with the original (it also no longer requires the Python driver to be installed, and only uses the standard library). I've done my best to annotate and comment it as well as possible, for future non-Pythonic maintainers.Viewing document elements in the VSCode variables tab
Viewing document content from the LLDB CLI
Introspection of a BSON binary and a BSON datetime
Decoding a Decimal128 value
Adding a watch expression in VSCode with CodeLLDB