Debian Codegraph @

docs/en/how-to/debugging/pdb.md

raw
1 # Debug via PDB { #debug-pdb }
2
3 You can use [PDB](https://docs.python.org/3/library/pdb.html) to debug a development app via `briefcase dev`, or a bundled app that is built via `briefcase build` and run via `briefcase run` - including mobile apps.
4
5 ## Development
6
7 To debug an app in development mode, add `breakpoint()` to your code somewhere that will be executed, and start the app with `briefcase dev`. When the breakpoint is reached, the PDB console will open in your terminal and you can debug your app.
8
9 ## Bundled App
10
11 /// warning | Note
12
13 This is currently an **experimental feature** that is only supported on Windows, macOS, iOS and Android.
14
15 ///
16
17 To debug a bundled app, add `breakpoint()` somewhere in your code where the debugger should halt.
18
19 Your app must then be modified to include a bootstrap that will connect to the VS Code debugger. This is done by passing the `--debug pdb` option to `briefcase build`:
20
21 ```console
22 $ briefcase build --debug pdb
23 ```
24
25 To build a mobile app, include the platform name in the `build` command - for example:
26
27 ```console
28 $ briefcase build iOS --debug pdb
29 ```
30
31 This will build your app in debug mode, adding [`remote-pdb`](https://pypi.org/project/remote-pdb/), and a package that automatically starts `remote-pdb` on startup of your bundled app.
32
33 You can then run your app in debug mode:
34
35 ```console
36 $ briefcase run --debug pdb
37 ```
38
39 To run a mobile app, include the platform name in the `run` command - for example:
40
41 ```console
42 $ briefcase run iOS --debug pdb
43 ```
44
45 Running the app in debug mode will automatically start the `remote-pdb` debugger and wait for incoming connections. By default, it will listen on `localhost` and port `5678`. In a separate terminal on your host system, connect to your bundled app:
46
47 /// tab | macOS
48
49 ```console
50 $ nc localhost 5678
51 ```
52
53 ///
54
55 /// tab | Linux
56
57 ```console
58 $ nc localhost 5678
59 ```
60
61 ///
62
63 /// tab | Windows
64
65 To connect to your application, you need access to `telnet`. `telnet` is not enabled by default; it can be activated by running the following command with admin rights:
66
67 ```console
68 $ dism /online /Enable-Feature /FeatureName:TelnetClient
69 ```
70
71 You can then start the connection with:
72
73 ```console
74 $ telnet localhost 5678
75 ```
76
77 ///
78
79 The app will start after the connection is established. When a breakpoint is reached, the PDB prompt will be displayed, allowing you to interact with the app.