mirror of
https://github.com/pocketpy/pocketpy
synced 2025-11-05 11:10:17 +00:00
Compare commits
No commits in common. "7135e1ce59239a88bcf664170ed63a617292a799" and "aa03544d4bb750c77531d20205f10c8eadcc229f" have entirely different histories.
7135e1ce59
...
aa03544d4b
@ -4,85 +4,8 @@ title: Debugging
|
|||||||
order: 80
|
order: 80
|
||||||
---
|
---
|
||||||
|
|
||||||
## Install VSCode Extension
|
## VSCode Extension
|
||||||
|
|
||||||
To debug a pocketpy program, you need to install our VSCode extension first:
|
You can install our VSCode extension to debug pocketpy scripts.
|
||||||
|
|
||||||
https://marketplace.visualstudio.com/items?itemName=pocketpy.pocketpy
|
https://marketplace.visualstudio.com/items?itemName=pocketpy.pocketpy
|
||||||
|
|
||||||
!!!
|
|
||||||
The VSCode extension requires pocketpy version >= `2.1.1`
|
|
||||||
!!!
|
|
||||||
|
|
||||||
## Create a `launch.json` file
|
|
||||||
|
|
||||||
Navigate to the Debug view in VSCode, and click on "create a launch.json file" link.
|
|
||||||
In the dropdown menu, select "pocketpy".
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
Then a default `launch.json` file will be created in the `.vscode` folder
|
|
||||||
with a sample pocketpy debug configuration.
|
|
||||||
|
|
||||||
## How does it work?
|
|
||||||
|
|
||||||
pocketpy provides a C-API `py_debugger_waitforattach`,
|
|
||||||
which starts a debug server and waits for the VSCode extension to attach.
|
|
||||||
When the debugger is attached, the program will continue to run.
|
|
||||||
|
|
||||||
+ If you are using pocketpy's standalone executable `main.exe`, you can pass `--debug` flag to it. This will automatically call `py_debugger_waitforattach("localhost", 6110)` before running your program.
|
|
||||||
+ If you are embedding pocketpy as a library, you need to call `py_debugger_waitforattach` manually in your C/C++ code.
|
|
||||||
|
|
||||||
## Configuration
|
|
||||||
|
|
||||||
+ `type`: must be `pocketpy`
|
|
||||||
+ `request`: can be `attach` or `launch`
|
|
||||||
+ `name`: the name of this configuration
|
|
||||||
+ `port`: the port number of the debug server, must match the one in `py_debugger_waitforattach`
|
|
||||||
+ `host`: the host of the debug server, must match the one in `py_debugger_waitforattach`
|
|
||||||
+ `sourceFolder`: the root folder of your python source code, default to `${workspaceFolder}`. However,
|
|
||||||
sometimes you may run your program from a subfolder, in this case you need to set `sourceFolder` to the correct path. If this is not set correctly, breakpoints will not be hit.
|
|
||||||
+ `program`: (for launch mode only) the path to the executable file which calls `py_debugger_waitforattach`, e.g. the pocketpy standalone executable `main.exe`.
|
|
||||||
+ `args`: (for launch mode only) the arguments to pass to the executable file, e.g. `--debug` and the script path if you are using `main.exe`.
|
|
||||||
+ `cwd`: (for launch mode only) the working directory to launch the executable file, default to `${workspaceFolder}`.
|
|
||||||
|
|
||||||
### For attach mode
|
|
||||||
|
|
||||||
In this mode, you need to start your pocketpy program manually which must call `py_debugger_waitforattach` first.
|
|
||||||
After the program starts, you can let VSCode attach to the debug server.
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"type": "pocketpy",
|
|
||||||
"request": "attach",
|
|
||||||
"name": "Attach to pocketpy program",
|
|
||||||
"port": 6110,
|
|
||||||
"host": "localhost",
|
|
||||||
"sourceFolder": "${workspaceFolder}"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### For launch mode
|
|
||||||
|
|
||||||
In this mode, VSCode will start your program with the specified `program`, `args` and `cwd`.
|
|
||||||
After the program starts, VSCode attempts to attach to the debug server automatically.
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"type": "pocketpy",
|
|
||||||
"request": "launch",
|
|
||||||
"name": "Launch pocketpy program",
|
|
||||||
"port": 6110,
|
|
||||||
"host": "localhost",
|
|
||||||
"sourceFolder": "${workspaceFolder}",
|
|
||||||
"program": "${workspaceFolder}/pocketpy/main.exe",
|
|
||||||
"args": [
|
|
||||||
"--debug"
|
|
||||||
],
|
|
||||||
"cwd": "${workspaceFolder}"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Showcase
|
|
||||||
|
|
||||||

|
|
||||||
|
|||||||
@ -17,13 +17,7 @@ which records the time spent for each line. To visualize the report, please inst
|
|||||||
|
|
||||||
https://marketplace.visualstudio.com/items?itemName=pocketpy.pocketpy
|
https://marketplace.visualstudio.com/items?itemName=pocketpy.pocketpy
|
||||||
|
|
||||||
!!!
|
|
||||||
The VSCode extension requires pocketpy version >= `2.1.1`
|
|
||||||
!!!
|
|
||||||
|
|
||||||
With pocketpy VSCode extension, press `F1` and type `pocketpy: Load Line Profiler Report`,
|
With pocketpy VSCode extension, press `F1` and type `pocketpy: Load Line Profiler Report`,
|
||||||
select **1. the `profile_report.json` file; 2. the source root of the program**. Then you will see a nice visualization of the profiling result.
|
select **1. the `profile_report.json` file; 2. the source root of the program**. Then you will see a nice visualization of the profiling result.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
Press `ESC` to exit the report view.
|
|
||||||
|
|||||||
@ -3,7 +3,7 @@ output: .retype
|
|||||||
url: https://pocketpy.dev
|
url: https://pocketpy.dev
|
||||||
branding:
|
branding:
|
||||||
title: pocketpy
|
title: pocketpy
|
||||||
label: v2.1.1
|
label: v2.1.0
|
||||||
logo: "./static/logo.png"
|
logo: "./static/logo.png"
|
||||||
favicon: "./static/logo.png"
|
favicon: "./static/logo.png"
|
||||||
meta:
|
meta:
|
||||||
|
|||||||
BIN
docs/static/debugger/debugger_demo.png
vendored
BIN
docs/static/debugger/debugger_demo.png
vendored
Binary file not shown.
|
Before Width: | Height: | Size: 582 KiB |
BIN
docs/static/debugger/launch_json.png
vendored
BIN
docs/static/debugger/launch_json.png
vendored
Binary file not shown.
|
Before Width: | Height: | Size: 263 KiB |
@ -5,20 +5,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
// https://jfdube.wordpress.com/2011/10/12/hashing-strings-and-pointers-avoiding-common-pitfalls/
|
#define HASH_KEY(__k) ((uintptr_t)(__k) >> 3U)
|
||||||
uintptr_t ThomasWangInt32Hash(void* Ptr) {
|
|
||||||
// Here we think only the lower 32 bits are useful
|
|
||||||
uint32_t Value = (uint32_t)(uintptr_t)Ptr;
|
|
||||||
Value = ~Value + (Value << 15);
|
|
||||||
Value = Value ^ (Value >> 12);
|
|
||||||
Value = Value + (Value << 2);
|
|
||||||
Value = Value ^ (Value >> 4);
|
|
||||||
Value = Value * 2057;
|
|
||||||
Value = Value ^ (Value >> 16);
|
|
||||||
return Value;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define HASH_KEY(__k) ThomasWangInt32Hash(__k)
|
|
||||||
|
|
||||||
#define HASH_PROBE_0(__k, ok, i) \
|
#define HASH_PROBE_0(__k, ok, i) \
|
||||||
ok = false; \
|
ok = false; \
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user