This directory contains examples showing how to use the Dapper debugger in different scenarios.
The integrated_debugging.py example demonstrates how to integrate the Dapper debugger directly into a Python program, rather than using it as an external debug adapter.
- Direct Integration: Shows how to embed debugging capabilities into your application
- Programmatic Breakpoints: Set breakpoints programmatically with conditions
- Event Handling: Custom event handlers for debug events
- Variable Inspection: Access and inspect variables during execution
- Execution Control: Control program flow during debugging
# Run with integrated debugging
python examples/integrated_debugging.py
# Run without debugging for comparison
python examples/integrated_debugging.py --no-debugThe example creates a custom debugger that:
- Sets breakpoints at specific lines in the code
- Handles debug events like breakpoints being hit and exceptions
- Inspects variables during execution
- Controls execution flow with conditional breakpoints
- Provides real-time feedback about the debugging process
DebugEventHandler: Handles debug events and provides feedbackIntegratedDebugger: Extends the base debugger with custom functionality- Example functions: Demonstrate different debugging scenarios
This approach is useful for:
- Long-running applications that need debugging capabilities
- Custom debug interfaces and UIs
- Testing frameworks that need programmatic debugging
- Development tools that integrate debugging features
- Educational purposes to understand debugging internals
| Feature | External Debugging | Integrated Debugging |
|---|---|---|
| Setup | Requires debug adapter protocol | Direct code integration |
| Control | External client controls debugging | Program controls its own debugging |
| Flexibility | Limited to DAP capabilities | Full programmatic control |
| Use Case | IDE integration, remote debugging | Embedded debugging, custom tools |
The example will:
- Set up custom breakpoints
- Run example functions with debugging enabled
- Show breakpoint hits and variable values
- Demonstrate exception handling
- Provide a summary of the debug session
Output will show:
- Breakpoint setup confirmations
- Execution flow with debug events
- Variable inspection results
- Exception handling
- Session summary
You can extend this example by:
- Adding more sophisticated event handlers
- Implementing custom breakpoint conditions
- Adding variable watching capabilities
- Integrating with UI frameworks
- Adding logging and monitoring features
The test_example.py script provides a simple way to verify that the example works correctly. Run it with:
python examples/test_example.pyRun the Debug Adapter on a background thread while your program keeps control of the main thread. Attach with a DAP client (e.g., VS Code) using debugServer.
Files:
adapter_in_thread.py— starts the adapter in a background thread on an ephemeral TCP port and runs a simple main-loop workload.inprocess_launch.json— sample VS Code launch configuration that setsinProcess: trueand can be adapted to attach to the adapter usingdebugServer.
Usage:
python examples/adapter_in_thread.pyThen configure your DAP client to attach:
- Note the printed
tcp://127.0.0.1:<PORT>from the script. - In VS Code, create or adapt a launch configuration with:
"request": "launch"and"debugServer": <PORT>"inProcess": trueto enable in-process mode- Set
"program"to the script you want to run under debug control (or omit if you only need attach semantics).
See examples/inprocess_launch.json for a minimal configuration.
Demonstrates how to implement and register a session-aware command provider that handles custom commands dispatched via SessionState.
Files:
simple_command_provider.py— minimal provider that implements two commands:helloandsum.
Provider contract:
supported_commands()returns the set of commands the provider can handle. Alternatively, implementcan_handle(command: str) -> bool.handle(session, command, arguments, full_command)returns either:- a dict containing a
successkey (the session will synthesize a response using the incoming commandid, if present), or Noneif the provider has already sent messages (events/responses) itself.
- a dict containing a
Usage:
uv run python examples/simple_command_provider.pyWhat you’ll see:
- A synthesized response for
hellothat includes a greeting body - A synthesized response for
sumwith the computed total - An error response for an unknown command
demo_restart.py spins up a local Dapper server, launches in-process, and then
issues a restart request. You’ll see the response and a terminated event
with restart: true in the console output.
Run it with:
uv run python examples/demo_restart.pyYou can attach to a running debuggee that exposes an IPC endpoint (TCP, Unix socket, or Windows named pipe). Create a VS Code configuration with "request": "attach", set useIpc: true, and provide the appropriate transport fields (ipcHost/ipcPort, ipcPath, or ipcPipeName). See the main README.md for copy/paste attach snippets.
demo_set_variable.py is a simple script to try out the setVariable capability.
It initializes variables of different types, prints them, and suggests edits you
can make from your debugger when stopped at the marked breakpoint.
Run it with:
uv run python examples/demo_set_variable.pyTips:
- Set a breakpoint where indicated in the file (near the first print block)
- Use your debugger's Set Value / setVariable command to change values like
x,y,z,pi,flag, anddata - Continue execution to see the "After" output reflect your changes
demo_enhanced_set_variable.py expands on the basic demo and shows editing:
- Object attributes (e.g.,
person.name,person.age) - List elements (e.g.,
numbers[0]) - Nested dictionary values (e.g.,
user_data['settings']['theme']) - Expression-based updates (e.g.,
age = age + 1)
Run it with:
uv run python examples/demo_enhanced_set_variable.pySet a breakpoint where indicated and try the suggested modifications listed in the comments to exercise the enhanced behavior.
The examples/sample_programs/ folder contains small scripts used by examples
and manual testing:
simple_app.py— a minimal program with a loop and function callsloop_example.py— small focused script that emphasises for/while loops and is handy when you want to try expression breakpoints without navigating a larger fileadvanced_app.py— a slightly richer flow for stepping and breakpointssubprocess_parent.py/subprocess_child.py— a parent/child pair for manualsubprocessAutoAttachverification across two debug sessionsset_variable_example.py— a concentrated target for setVariable testing
You can run them directly, for example:
uv run python examples/sample_programs/simple_app.pySee examples/sample_programs/README.md for any additional notes.