-
Notifications
You must be signed in to change notification settings - Fork 0
[#1] Add new README at top level #2
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,149 @@ | ||
| # **Debugging Python Scripts with UDB** | ||
|
|
||
| This guide explains how to use UDB to debug Python scripts using the `python` addon. | ||
|
|
||
| --- | ||
|
|
||
| ## **Prerequisites** | ||
|
|
||
| You will need: | ||
|
|
||
| * A working UDB installation | ||
| * The path to your Python interpreter (e.g. `/usr/bin/python`) | ||
| * The Python script you want to debug | ||
|
|
||
| ## **Step 1: Start UDB with the Python Interpreter** | ||
|
|
||
| Rather than running your Python script directly, launch UDB with your Python interpreter as the target program: | ||
|
|
||
| ``` | ||
| udb /path/to/python | ||
| - or - | ||
| udb `which python` | ||
| ``` | ||
nickatundo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| Note: If using pyenv, use: | ||
| ```bash | ||
| udb `pyenv which python` | ||
| ``` | ||
|
|
||
| ## **Step 2: Install the Python Addon** | ||
|
|
||
| At the UDB prompt, install the Python debugging addon: | ||
|
|
||
| ``` | ||
| not running> extend python | ||
| ``` | ||
|
|
||
| UDB will download and set up the addon automatically. | ||
|
|
||
| ⚠️ **Note:** The `python` addon is experimental and may change in incompatible ways in future releases. | ||
|
|
||
| ## **Step 3: Start Your Script** | ||
|
|
||
| Use the `upy start` command to load and begin recording your Python script: | ||
|
|
||
| ``` | ||
| not running> upy start /path/to/your_script.py [arguments] | ||
| ``` | ||
|
|
||
| For example: | ||
|
|
||
| ``` | ||
| not running> upy start /home/user/scripts/fizzbuzz.py 20 | ||
| ``` | ||
|
|
||
| UDB will initialize the Python environment and begin recording execution. You'll see a prompt like: | ||
|
|
||
| ``` | ||
| Python has been initialized. | ||
| recording 5,048,331> | ||
| ``` | ||
|
|
||
| ## **Navigating the Recording** | ||
|
|
||
| Once your script is running, you have two sets of commands available: | ||
|
|
||
| ### **Standard UDB commands** | ||
|
|
||
| Use these to navigate at the **C level** (the underlying interpreter execution). For example: | ||
|
|
||
| * `continue`, `next`, `step` — move forward | ||
| * `reverse-continue`, `reverse-next` — move backward | ||
| * `break` — set a C-level breakpoint | ||
| * `layout dashboard` — enable the dashboard TUI layout | ||
| * `Last <expression>` — travel backwards to the last time \<expression\> changed | ||
|
|
||
|
|
||
|
|
||
| ### **Python-level commands (prefixed with `upy`)** | ||
|
|
||
| Use these to navigate at the **Python level** (your script's source code). For example: | ||
|
|
||
| | Command | Description | | ||
| | ----- | ----- | | ||
| | `upy continue` | Run forward until the next breakpoint or end of program | | ||
| | `upy reverse-continue` | Run backward until the previous breakpoint | | ||
| | `upy next` | Step forward to the next Python line | | ||
| | `upy reverse-next` | Step backward to the previous Python line | | ||
| | `upy break <function>` | Set a Python breakpoint at a function | | ||
| | `upy break <file.py:line>` | Set a Python breakpoint at a line in `file.py` | | ||
| | `upy start <script> [args]` | Start a Python script | | ||
|
|
||
| **Example session** — running a script, setting a breakpoint, and stepping back through it: | ||
|
|
||
| ``` | ||
| recording> upy continue | ||
| # ... script output ... | ||
|
|
||
| end> upy break fizzbuzz | ||
| Python breakpoint 1 at fizzbuzz () | ||
|
|
||
| end> upy reverse-continue | ||
| Python breakpoint 1, fizzbuzz () at /home/user/scripts/fizzbuzz.py:4 | ||
| #0 File "fizzbuzz.py", line 4, in fizzbuzz | ||
| for i in range(1, max + 1): | ||
|
|
||
| > upy next | ||
| #0 File "fizzbuzz.py", line 5, in fizzbuzz | ||
| if i % 3 == 0 and i % 5 == 0: | ||
| ``` | ||
|
|
||
| ## **TUI Layout** | ||
|
|
||
| For a visual, source-level debugging interface, type: | ||
|
|
||
| ``` | ||
| layout python | ||
| ``` | ||
|
|
||
| This opens a terminal UI showing your Python source code as you step through it, similar to `layout dashboard` for C-level debugging. | ||
|
|
||
| ## **Getting Help** | ||
|
|
||
| To see all available Python debugging commands, type: | ||
|
|
||
| ``` | ||
| help upy | ||
| ``` | ||
|
|
||
| ## **Quick Reference** | ||
|
|
||
| ``` | ||
| udb `which python` # Launch UDB with Python | ||
| udb /path/to/python # Launch UDB with Python | ||
| extend python # Load the Python addon | ||
| upy start script.py [args] # Start and record your script | ||
| upy continue # Run forward | ||
| upy reverse-continue # Run backward | ||
| upy next # Step to next Python line | ||
| upy break <function> # Set a Python breakpoint | ||
| upy break <file.py:line> # Set a Python breakpoint | ||
| upy watch <expression> # Set a Python watchpoint | ||
| upy info locals # Display Python local variables | ||
| upy backtrace # Display Python backtrace | ||
| layout python # Open Python TUI view | ||
| layout dashboard # Open C/C++ TUI view | ||
| help upy # Show all upy commands | ||
| ``` | ||
|
|
||
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@FinnG I'm not sure if the pyproject.toml file is doing anything useful at this point - should we just get rid?
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.
I think perhaps we might want to keep it if we support building our own version of the library and passing it into
udbvia environment variable? I have a patch for this, so can look at thepyproject.tomlfile as part of that.