|
| 1 | +--- |
| 2 | +title: "Implementing Debugging Support for xeus-cpp" |
| 3 | +layout: post |
| 4 | +excerpt: "A GSoC 2025 project aiming at integration of debugger into the xeus-cpp kernel for Jupyter using LLDB and its Debug Adapter Protocol (lldb-dap)." |
| 5 | +sitemap: true |
| 6 | +author: Abhinav Kumar |
| 7 | +permalink: blogs/gsoc25_abhinav_kumar_final_blog/ |
| 8 | +banner_image: /images/blog/gsoc-banner.png |
| 9 | +date: 2025-11-14 |
| 10 | +tags: gsoc c++ debugger dap clang jupyter clang clang-repl |
| 11 | +--- |
| 12 | + |
| 13 | +## Introduction |
| 14 | +Hello! I’m Abhinav Kumar, and this summer I had the exciting opportunity to participate in Google Summer of Code (GSoC) 2025. My project revolved around implementing debugging support for xeus-cpp kernel. |
| 15 | + |
| 16 | +## Project Overview |
| 17 | +`xeus-cpp` is a C++ Jupyter kernel that enables interactive C++ execution within JupyterLab. |
| 18 | +My project focused on integrating a full-fledged **debugger** into the `xeus-cpp` kernel, enabling users to perform interactive debugging directly from JupyterLab. |
| 19 | + |
| 20 | +The debugger integration is powered by **LLDB-DAP** - the Debug Adapter Protocol implementation for the LLDB debugger. However, directly attaching LLDB-DAP to the kernel process causes the kernel to pause and terminate. |
| 21 | +To address this, the project leverages **out-of-process JIT execution**, inspired by [Clang-Repl’s Out-of-Process Execution model](https://compiler-research.org/blogs/gsoc24_sahil_wrapup_blog/). |
| 22 | + |
| 23 | +With this design, users can now seamlessly: |
| 24 | +- Set and hit breakpoints |
| 25 | +- Inspect variables |
| 26 | +- Step through code (step in, step out, continue) |
| 27 | +- Debug C++ programs interactively |
| 28 | + |
| 29 | +all within **JupyterLab**, using the `xeus-cpp` kernel. |
| 30 | + |
| 31 | +## Overview of the Work Done |
| 32 | + |
| 33 | +### JupyterLab |
| 34 | +#### **Pull Request**: [Fix threadId being passed to the debugger #17667](https://github.com/jupyterlab/jupyterlab/pull/17667) |
| 35 | +Identified and fixed a bug in JupyterLab’s frontend debugger implementation. |
| 36 | +Previously, the [`DebuggerService::_currentThread`](https://github.com/jupyterlab/jupyterlab/blob/72410ce1ac956d4da1769b428de369e84e0b6c17/packages/debugger/src/service.ts#L754) method returned a hardcoded value of `1`. |
| 37 | +This was corrected to dynamically return the first available `threadId`, ensuring accurate thread handling during debugging sessions. |
| 38 | + |
| 39 | +#### **Issue**: [Bug: Multiple configurationDone Requests Sent by JupyterLab #17673](https://github.com/jupyterlab/jupyterlab/issues/17673) |
| 40 | +Discovered that JupyterLab was sending a `configurationDone` request after every `setBreakpoints` call. |
| 41 | +According to the Debug Adapter Protocol (DAP) specification, this request should only be sent **once**, after all initial configuration is complete. |
| 42 | +This issue was reported and documented for further upstream resolution. |
| 43 | + |
| 44 | +--- |
| 45 | + |
| 46 | +### CppInterOp |
| 47 | +#### **Pull Request**: [Documentation for debugging CppInterOp using LLDB #621](https://github.com/compiler-research/CppInterOp/pull/621) |
| 48 | +Added comprehensive documentation describing how to debug **CppInterOp** using **LLDB**, making it easier for developers to inspect and troubleshoot CppInterOp internals. |
| 49 | + |
| 50 | +#### **Pull Request**: [Out-Of-Process Interpreter for CppInterOp #717](https://github.com/compiler-research/CppInterOp/pull/717) |
| 51 | +Implemented an **Out-of-Process Interpreter** for CppInterOp. |
| 52 | +This enhancement utilizes LLVM’s `llvm-jitlink-executor` and the **ORC Runtime** to delegate JIT execution to a separate process. |
| 53 | +Users can enable this functionality simply by passing the `--use-oop-jit` flag as a `ClangArg` when constructing the interpreter. |
| 54 | + |
| 55 | +--- |
| 56 | + |
| 57 | +### LLVM Project |
| 58 | +#### **Pull Request**: [[clang-repl] Adds custom lambda in launchExecutor and PID retrieval](https://github.com/llvm/llvm-project/pull/152562) *(Merged but later reverted by [#153180](https://github.com/llvm/llvm-project/pull/153180))* |
| 59 | +Introduced: |
| 60 | +1. A **custom lambda function** in `launchExecutor`. |
| 61 | +2. Support for **retrieving the PID** of the launched out-of-process (OOP) JIT executor. |
| 62 | + |
| 63 | +However, due to issues with the testing infrastructure, the PR was reverted. |
| 64 | + |
| 65 | +#### **Subsequent Pull Requests** |
| 66 | +- [[clang-repl] Sink RemoteJITUtils into Interpreter class (NFC) #155140](https://github.com/llvm/llvm-project/pull/155140) |
| 67 | +- [[clang-repl] Add support for running custom code in Remote JIT executor #157358](https://github.com/llvm/llvm-project/pull/157358) |
| 68 | +- [[clang-repl] Disable out of process JIT tests on non-unix platforms #159404](https://github.com/llvm/llvm-project/pull/159404) |
| 69 | + |
| 70 | +These follow-up PRs addressed the functionality of the reverted change by: |
| 71 | +1. **Refactoring `RemoteJITUtils`**, creating the `JitBuilder` inside the `Interpreter` class. |
| 72 | +2. **Adding support for custom lambdas** in `launchExecutor`. |
| 73 | +3. **Enabling PID retrieval** for the launched OOP JIT executor. |
| 74 | +4. **Improving test reliability** by disabling OOP JIT tests on non-Unix platforms. |
| 75 | + |
| 76 | +--- |
| 77 | + |
| 78 | +### **xeus-cpp** |
| 79 | +> The changes in *xeus-cpp* are currently awaiting review and merge. |
| 80 | +
|
| 81 | +#### **Pull Request:** [Debugger for xeus-cpp with testing framework #401](https://github.com/compiler-research/xeus-cpp/pull/401) |
| 82 | + |
| 83 | +This pull request introduces comprehensive debugger support for the *xeus-cpp* kernel. |
| 84 | + |
| 85 | +**Key contributions include:** |
| 86 | +1. A new kernel variant with an out-of-process interpreter and integrated debugger support. |
| 87 | +2. Integration of LLDB-DAP within the *xeus* environment. |
| 88 | +3. A dedicated testing framework to validate and ensure the reliability of debugger functionality. |
| 89 | + |
| 90 | +## Demo |
| 91 | +### Docker Image |
| 92 | +The provided Docker image is based on **Ubuntu 22.04 (x86_64)**. You can run it on any x86_64 host machine. |
| 93 | +When launched, it automatically starts a **JupyterLab** instance configured with the **xcpp17-debugger** kernel, allowing you to experiment with the debugger directly. |
| 94 | + |
| 95 | +#### **Commands to Run** |
| 96 | +```bash |
| 97 | +docker pull kr2003/xcpp-debugger |
| 98 | +``` |
| 99 | +```bash |
| 100 | +docker run -it --privileged -p 8888:8888 kr2003/xcpp-debugger |
| 101 | +``` |
| 102 | + |
| 103 | +Once the container starts, open `localhost:8888` in your browser to access JupyterLab and try out the debugger. |
| 104 | + |
| 105 | +### Video Demo |
| 106 | +[Video demo of xeus-cpp debugger](https://drive.google.com/file/d/1pQZk4OESNQe43LOa4IzZLS1-XfUvXE8e/view?usp=sharing) |
| 107 | + |
| 108 | +## Future Works |
| 109 | +1. **Merge the xeus-cpp debugger support:** Finalize and merge the pending PR by breaking it into 2–3 incremental PRs for better review and integration. |
| 110 | +2. **Explore LLDB in WebAssembly:** Investigate the feasibility of running LLDB in WASM and adding debugger (DAP) support in JupyterLite. |
| 111 | +3. **Enhance LLDB-DAP for advanced C++ debugging:** Extend DAP functionality to include advanced C++ debugging features such as watchpoints and data breakpoints. |
| 112 | +4. **Optimize the out-of-process interpreter:** Improve performance by leveraging shared memory for communication between processes. |
| 113 | +5. **Expand architecture support:** Extend the out-of-process interpreter to additional architectures beyond Linux x86_64 and macOS Darwin. |
| 114 | + |
| 115 | +I look forward to continuing contributions beyond GSoC, particularly towards implementing new features and improvements in **clang-repl** and **CppInterOp**. |
| 116 | + |
| 117 | +## Conclusion |
| 118 | +Participating in Google Summer of Code 2025 has been an incredibly enriching experience. |
| 119 | +Throughout the program, I gained a deeper understanding of how interactive execution, debugging, and JIT compilation work together within the LLVM and Jupyter ecosystems. |
| 120 | + |
| 121 | +This project not only strengthened my skills in **systems programming**, **compiler internals**, and **debugger integration**, but also gave me the opportunity to collaborate with an inspiring community of developers and mentors at **CERN-HSF**. |
| 122 | + |
| 123 | +I’m grateful to my mentors — **Anutosh Bhat**, **Vipul Cariappa**, and **Vassil Vassilev** — for their constant support, insightful reviews, and guidance throughout the project. |
| 124 | + |
| 125 | +While the foundation for debugger support in `xeus-cpp` has been successfully implemented, there remains exciting future work to further refine and expand its capabilities. |
| 126 | +I look forward to continuing my contributions to **xeus-cpp**, **CppInterOp**, and **clang-repl**, and to further advancing open-source compiler and debugging infrastructure. |
| 127 | + |
0 commit comments