Enable SGX Debugging in VS Code

2021/06/04

Intel has provided sgx-gdb for conveniently debugging SGX applications. However, it can only be interacted via terminal, which may be a little bit hard for beginners. This article introduces how to debug SGX applications in VS Code.

Prerequisites

Steps

  1. Open the SGX project folder with your VS Code, and click the following icon in the left sidebar (or press Ctrl+Shift+D) to open RUN AND DEBUG window.
  2. Add a new configuration, and then an launch.json file will be opened.
  3. Copy the following lines to the file:
{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(sgx) Debug",
            "type": "gdb",
            "request": "launch",
            "target": "app",
            "cwd": "${workspaceRoot}/",
            "valuesFormatting": "parseText",
            "gdbpath": "sgx-gdb"
        }
    ]
}

This configuration assumes that your executable file is named as app and at the root directory of your project. If not, please modify the cwd (current working directory) and target (executable binary) values.

  1. Add any breakpoint in your code and try it!