Skip to content

Debugging HXCPP

m0rkeulv edited this page Oct 25, 2026 · 3 revisions

The HXCPP debuggers debug desktop programs compiled to C++ with hxcpp. The debugging code is a Haxe library that you compile into your program; when you debug, it connects to the IDE. The plugin offers three run configurations, one per debug library. For the workflow all debuggers share, see Debugging Overview.

Which configuration to use

Run configuration Library compiled into your program Use it when
HXCPP Application (IntelliJ) intellij-hxcpp-debug-server You start a new setup. This is the recommended one.
HXCPP Application (vshaxe) hxcpp-debug-server, the library the VS Code hxcpp debugger uses Your project is also debugged in VS Code and you don't want to change its build.
HXCPP Application (legacy) the old debugger library A project set up with plugin version 1.x still uses it.

The IntelliJ and vshaxe configurations start the program from the IDE. Attaching to a program that is already running is not supported.

Requirements

  • Haxe 4.1 or later.

  • The hxcpp library and a C++ compiler. Install hxcpp with haxelib install hxcpp. On Windows use Visual Studio, on macOS Xcode and on Linux your distribution's compiler packages. The Haxe manual's page Getting started with Haxe/C++ has the details.

  • The debug library of the configuration you use. The IntelliJ one is published on lib.haxe.org:

    haxelib install intellij-hxcpp-debug-server

    You can also install it from the run configuration: when the library is missing, the editor shows The intellij-hxcpp-debug-server haxelib is not installed — with an Install link. The HXCPP Application (vshaxe) configuration shows the same for hxcpp-debug-server.

HXCPP Application (IntelliJ)

Build for debugging

Compile with -debug and the intellij-hxcpp-debug-server library. The library sets up everything else it needs.

When you debug an HXCPP Application (IntelliJ) configuration with a Run Haxe action step, the plugin adds these arguments for you: -debug -lib intellij-hxcpp-debug-server for hxml files, -debug --haxelib=intellij-hxcpp-debug-server for the Lime and OpenFL desktop targets and -debug --library intellij-hxcpp-debug-server for the NME desktop targets. See Debug builds are made for you.

You can also keep the flags in the build file. A program built with the library runs normally when you start it without the debugger.

-cp src
-main Main
-cpp bin
-debug
-lib intellij-hxcpp-debug-server

hxcpp adds -debug to the name of a debug build's executable, so this build produces bin/Main-debug.exe on Windows and bin/Main-debug on macOS and Linux.

Create the run configuration

Right-click the build file's Build & run entry in the Haxe tool window and choose Debug. For Lime, OpenFL and NME projects, select a desktop target (windows, mac, linux or cpp) first. This creates an HXCPP Application (IntelliJ) configuration and fills in the executable when the plugin can work out its path. For an hxml build, the executable is ${executable}, which the plugin works out at each launch, so the -debug suffix of a debug build is taken care of. If the plugin cannot work out the path, set Compiled executable: yourself.

An hxml build gets the Build & run entry only when it links an executable for this machine: not with static_link or dll_link, and not for another platform. Otherwise, or to set things up by hand, create the configuration yourself:

  1. Open Run | Edit Configurations…, click +, open the Haxe group and choose HXCPP Application (IntelliJ).
  2. Select the Module: and set Compiled executable: to the debug build's executable.
  3. Optional: under Before launch, add a Run Haxe action step for your hxml file, so the program is built before each launch. If the hxml already has the debug flags, turn off Add debug arguments when launched with Debug in the step.
Field What it does
Module: The module the program belongs to.
Compiled executable: The program to run. A relative path is resolved against the module's folder.
Working directory: Leave empty to use the executable's directory.
Program arguments: Arguments passed to the program.

There is no port to set: the IDE picks a free port for every session, so you can debug several programs at once.

What you can do

  • Line breakpoints, with conditions. A breakpoint on a line without code is shown as invalid, with the message no executable code at this line (stale build?).
  • Stepping: Step Over, Step Into, Step Out, Run to Cursor and Pause, plus Smart Step Into.
  • Threads: multi-threaded programs are supported. When the program stops, all threads stop.
  • Variables: each frame shows its arguments, local variables and this together. Arrays, objects, anonymous structures and enums can be expanded.
  • Set Value works in any frame and takes Bool, Int, Float and String values.
  • Evaluate Expression, watches, hover and breakpoint conditions run inside your program. They can call methods, use static fields through their package path (my.pack.Util.compute(x)), create objects with new and assign values. Changes stay after you resume.
  • Exception breakpoints: caught exceptions, uncaught exceptions and critical errors such as null access. See the limits below.
  • Render Objects with toString() labels objects with their own toString(). See Show objects with toString().

Variables reads fields directly and never runs property getters: a property with a stored value (@:isVar) shows that value, not what its getter would return. Use Evaluate Expression to call a getter.

Limitations

  • Stepping needs a breakpoint. hxcpp checks for steps only while at least one breakpoint is set. If you remove all breakpoints and then step, the program runs on.
  • A breakpoint on a one-line loop stops only once. In for (i in 0...n) total += i; the line never changes, so the breakpoint does not stop again. To stop on every pass, put the breakpoint inside a function the loop calls.
  • A line with several calls can stop more than once when you resume, because each call on the line is checked separately.
  • Call chains on one line: on a.first().second();, stepping out of first does not return to that line; it stops on the next line. Use Smart Step Into to pick calls on such a line.
  • Smart Step Into does not offer local functions, closures, inline methods or externs. A method that a subclass overrides, called through the base type, is stepped over.
  • Exception breakpoints:
    • Caught-exception and single-class breakpoints see only haxe.Exception and its subclasses. A value thrown directly, such as throw "error", is seen only when it is not caught.
    • With the caught option on, creating a haxe.Exception stops even if it is never thrown, and rethrowing an exception does not stop again.
    • With the critical-errors option on, a null access stops even inside a try that would catch it. Resuming after a critical error repeats the error or crashes the program.

HXCPP Application (vshaxe)

Use this configuration for programs built with hxcpp-debug-server, the debug library of the VS Code hxcpp debugger. Your build needs -debug -lib hxcpp-debug-server.

Field What it does
Module:, Compiled executable:, Program arguments: As for the IntelliJ configuration.
Working directory (empty = executable directory): The folder the program runs in.
Debug host (must match -D HXCPP_DEBUG_HOST): The host the program connects to. Default: 127.0.0.1.
Debug port (must match -D HXCPP_DEBUG_PORT): The port the program connects to. Default: 6972.

The program connects to the address it was compiled with, so the host and port must match the HXCPP_DEBUG_HOST and HXCPP_DEBUG_PORT defines of your build. Keep the defaults unless your build sets these defines.

When this configuration builds through a Run Haxe action step, a Debug launch adds -debug and -lib hxcpp-debug-server to the build for you.

A program built with hxcpp-debug-server waits for a debugger when you run it normally, and may keep running after main() ends. Use a build without the library for plain runs. A copy of the program that is still running blocks the debug port, and the next session fails, for example with a message that starts with Cannot listen on. Stop the old copy and try again.

Compared with the IntelliJ configuration, this one has these limits:

  • Set Value and assignments in Evaluate Expression work only for variables of the top frame.
  • Breakpoints are matched by the full path of the source file. A program compiled from another folder (a moved project, a build machine) does not stop at your breakpoints. Rebuild it locally.
  • Breakpoint lines are not checked; a breakpoint on a line without code simply never stops. That includes lines whose code the compiler optimized away; see Code the compiler optimized away.
  • Exception breakpoints cannot be configured. Uncaught exceptions always stop the program at the throw; this first stop looks like a pause. Resuming then reports the exception, or the program ends with its error.
  • No Smart Step Into, and no Render Objects with toString(): objects are always shown through Std.string().
  • A breakpoint on a line with an array comprehension, such as var items = [for (i in 0...n) i * 10];, stops once per element.

HXCPP Application (legacy)

This configuration keeps projects working that were set up with plugin version 1.x and the old debugger library. Migrated 1.x projects keep their C++ run configurations as this type; see Migrating from 1.x. For new setups, use the IntelliJ configuration.

Field What it does
Module: The module the program belongs to.
Executable: The program to run.
Program arguments: Arguments passed to the program.
Working directory: Empty means the executable's folder.
Debugger port: The port the IDE listens on. Default: 6972.
Remote debugging (listen only - the debugged process is started externally) The IDE only listens; you start the program yourself.

A Run Haxe action step adds only -debug for this configuration; the debugger library stays in your build file. On Debug, the IDE appends -start_debugger -debugger_host=localhost:<port> to the program's arguments. When you launch through Lime or OpenFL, end the arguments with -args so that these flags reach the program. In remote mode, start the program with the same two flags; a notification shows the port the IDE listens on.

The legacy debugger supports line breakpoints, stepping, pausing, variables and Evaluate Expression. It shows the stack of the current thread only. It has no breakpoint conditions, Run to Cursor, Set Value, Smart Step Into or exception breakpoints.

Clone this wiki locally