Skip to content

Commit 251d2a9

Browse files
committed
[#1] Add new README at top level
1 parent 4dfa686 commit 251d2a9

File tree

2 files changed

+150
-117
lines changed

2 files changed

+150
-117
lines changed

README.md

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
# **Debugging Python Scripts with UDB**
2+
3+
This guide explains how to use UDB to debug Python scripts using the `python` addon.
4+
5+
---
6+
7+
## **Prerequisites**
8+
9+
You will need:
10+
11+
* A working UDB installation
12+
* The path to your Python interpreter (e.g. `/usr/bin/python`)
13+
* The Python script you want to debug
14+
15+
## **Step 1: Start UDB with the Python Interpreter**
16+
17+
Rather than running your Python script directly, launch UDB with your Python interpreter as the target program:
18+
19+
```
20+
udb /path/to/python
21+
- or -
22+
udb `which python`
23+
```
24+
25+
Note: If using pyenv, use: `` udb `pyenv which python` ``
26+
27+
## **Step 2: Install the Python Addon**
28+
29+
At the UDB prompt, install the Python debugging addon:
30+
31+
```
32+
not running> extend python
33+
```
34+
35+
UDB will download and set up the addon automatically.
36+
37+
⚠️ **Note:** The `python` addon is experimental and may change in incompatible ways in future releases.
38+
39+
## **Step 3: Start Your Script**
40+
41+
Use the `upy start` command to load and begin recording your Python script:
42+
43+
```
44+
not running> upy start /path/to/your_script.py [arguments]
45+
```
46+
47+
For example:
48+
49+
```
50+
not running> upy start /home/user/scripts/fizzbuzz.py 20
51+
```
52+
53+
UDB will initialise the Python environment and begin recording execution. You'll see a prompt like:
54+
55+
```
56+
Python has been initialized.
57+
recording 5,048,331>
58+
```
59+
60+
## **Navigating the Recording**
61+
62+
Once your script is running, you have two sets of commands available:
63+
64+
### **Standard UDB commands**
65+
66+
Use these to navigate at the **C level** (the underlying interpreter execution). For example:
67+
68+
* `continue`, `next`, `step` — move forward
69+
* `reverse-continue`, `reverse-next` — move backward
70+
* `break` — set a C-level breakpoint
71+
* `layout dashboard` — enable the dashboard TUI layout
72+
* `Last <expression>` — travel backwards to the last time \<expression\> changed
73+
74+
75+
76+
###
77+
78+
### **Python-level commands (prefixed with `upy`)**
79+
80+
Use these to navigate at the **Python level** (your script's source code). For example:
81+
82+
| Command | Description |
83+
| ----- | ----- |
84+
| `upy continue` | Run forward until the next breakpoint or end of program |
85+
| `upy reverse-continue` | Run backward until the previous breakpoint |
86+
| `upy next` | Step forward to the next Python line |
87+
| `upy reverse-next` | Step backward to the previous Python line |
88+
| `upy break <function>` | Set a Python breakpoint at a function |
89+
| `upy break <file.py:line>` | Set a Python breakpoint at a line in `file.py` |
90+
| `upy start <script> [args]` | Start a Python script |
91+
92+
**Example session** — running a script, setting a breakpoint, and stepping back through it:
93+
94+
```
95+
recording> upy continue
96+
# ... script output ...
97+
98+
end> upy break fizzbuzz
99+
Python breakpoint 1 at fizzbuzz ()
100+
101+
end> upy reverse-continue
102+
Python breakpoint 1, fizzbuzz () at /home/user/scripts/fizzbuzz.py:4
103+
#0 File "fizzbuzz.py", line 4, in fizzbuzz
104+
for i in range(1, max + 1):
105+
106+
> upy next
107+
#0 File "fizzbuzz.py", line 5, in fizzbuzz
108+
if i % 3 == 0 and i % 5 == 0:
109+
```
110+
111+
##
112+
113+
## **TUI Layout**
114+
115+
For a visual, source-level debugging interface, type:
116+
117+
```
118+
layout python
119+
```
120+
121+
This opens a terminal UI showing your Python source code as you step through it, similar to `layout dashboard` for C-level debugging.
122+
123+
## **Getting Help**
124+
125+
To see all available Python debugging commands, type:
126+
127+
```
128+
help upy
129+
```
130+
131+
## **Quick Reference**
132+
133+
```
134+
udb `which python` # Launch UDB with Python
135+
udb /path/to/python # Launch UDB with Python
136+
extend python # Load the Python addon
137+
upy start script.py [args] # Start and record your script
138+
upy continue # Run forward
139+
upy reverse-continue # Run backward
140+
upy next # Step to next Python line
141+
upy break <function> # Set a Python breakpoint
142+
upy break <file.py:line> # Set a Python breakpoint
143+
upy watch <expression> # Set a Python watchpoint
144+
upy info locals # Display Python local variables
145+
upy backtrace # Display Python backtrace
146+
layout python # Open Python TUI view
147+
layout dashboard # Open C/C++ TUI view
148+
help upy # Show all upy commands
149+
```
150+

python/README.md

Lines changed: 0 additions & 117 deletions
This file was deleted.

0 commit comments

Comments
 (0)