Skip to content

Discussing Debugger Support For Xeus-cpp #282

Open
@anutosh491

Description

@anutosh491

Hey All,

I have been doing quite some back and forth with @kr-2003 for discussing some design details for the debugger. We think we've made quite some progress and would like to point out possible pain-points that came out of our discussion.

What has been achieved

We have already set up debugging in VSCode using LLDB-DAP. The following video demo showcases how JIT-compiled code can be debugged using LLDB, LLDB-DAP, and VSCode. For our project, we need to integrate LLDB-DAP with Jupyter Notebook.

debugg.1.mp4

Steps to replicate the above

PRE-REQUISITES : Install lldb and lldb-dap executable in your toolchain (should be pre-installed in macos). You can also install the lldb-dap extension for vs-code.

  1. Create a program and name it as test.cxx for starters
// jitcode_with_cppinterop.cpp
#include "clang/Interpreter/CppInterOp.h"
#include <iostream>


void run_code(std::string code) {
 Cpp::Declare(code.c_str());
}


int main(int argc, char *argv[]) {
 Cpp::CreateInterpreter({"-g", "-O0"});
 std::vector<Cpp::TCppScope_t> Decls;
 std::string code = R"(
#include <iostream>
void f2() {
 int a = 4;
 int b = 10;
 std::cout << b - a << std::endl;
 std::cout << "kr-2003" << std::endl;
}
void f3() {
 int a = 1;
 int b = 10;
 std::cout << b - a << std::endl;
 std::cout << "in f3 function" << std::endl;
}
f2();
f3();
int a = 100;
int b = 1000;


 )";
 std::cout << code << std::endl;
 return 0;
}
  1. Compile the above into an executable. We shall be attaching the debugger on this test executable
$LLVM_DIR/build/bin/clang++ -I$CPPINTEROP_DIR/include -g -O0 -lclangCppInterOp -Wl,-rpath,$CPPINTEROP_DIR/build/lib -L$CPPINTEROP_DIR/build/lib test.cxx -o test
  1. Create a launch.json to launch the debugger through VS-code
{
 "version": "0.2.0",
 "configurations": [
     {
         "type": "lldb-dap",
         "request": "launch",
         "name": "Debug",
         "program": "/Users/abhinavkumar/Desktop/Coding/Testing/test", // change according to your test executable
         "sourcePath" : ["${workspaceFolder}"],
         "cwd": "${workspaceFolder}",
         "initCommands": [
             "settings set plugin.jit-loader.gdb.enable on", // This is crucial 
         ]
     },
 ]
}

By default, the VS Code extension will expect to find lldb-dap in your PATH. Alternatively, you can explictly specify the location of the lldb-dap binary using the lldb-dap.executable-path setting.

  1. Create a input_line_1 file which acts as a source that the debugger uses for mapping addresses.

#include <iostream>
void f2() {
  int a = 4;
  int b = 10;
  std::cout << b - a << std::endl;
  std::cout << "kr-2003" << std::endl;
}
void f3() {
  int a = 1;
  int b = 10;
  std::cout << b - a << std::endl;
  std::cout << "in f3 function" << std::endl;
}
f2(); // applying breakpoiutn here
f3();
int a = 100;
int b = 1000;
  1. Try running the debugger through vs-code. You should be able to achieve the above demo shown where we are able to set breakpoints, continue and step in for a single cell of JIT compiled code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions