Search code examples
c++visual-studio-codecmakevscode-debugger

C++ debugging using generated parent files (lzz, vscode)


I'm using lzz to generate .hpp and .cpp files from header-only files in my project. (lets call them .hpp_dev)

CMake is used to build the generated files into libraries, which are then linked to executables.

When I run the executables under vscode debug configuration, errors and breakpoints always refers to lines in the generated files.

Is it possible to get the debug interface back onto the development headers? (i.e. set breakpoints in .hpp_dev, get referred to errors in the .hpp_dev file instead of in the .cpp generated implementation)


Solution

  • The lzz preprocessor tool has 4 options which actually generates #line directives in the different output file types:

    ... 
    -hl Generate #line directives in the header file.
    -sl Generate #line directives in the source file.
    -il Generate #line directives in the inline file.
    -tl Generate #line directives in the template file
    

    The generated #line directives refers the vscode debugger back to the development header, which solves both breakpoint and runtime error feedback.