VSCode and Debugger

Has anyone figured out how to enable debugging, breakpoints etc using VSCode? I can see people have figured it out for Visual Studio (full) here Helpful Tip: Visual Studio Debugging

I am running VSCode on OSX.

I haven't done it personally, but you can use the Makefile VSCode plugin (provided by Microsoft) and set it up to run and debug in VSCode. Here is a good write up on getting it set up. If you're looking for Lua instructions, they are here.

Tried both of these suggestions. Both of them let you start the simulator from within VSCode but neither let you attach the debugger.

You'd have to set your compilerPath in your VSCode properties file to gcc but then launch the Simulator with the game path as the arguments going to gcc. If I have time I'll mess with it a bit tomorrow and see if I can get it working. That said, you can use Xcode on macOS to debug games which is a bit more straight forward. :slight_smile:

I was able to get this to work. My approach was:

  1. Make sure you can build C_API/Examples/Hello World using CMake from the Terminal. This will ensure that you have all the right tools installed correctly (CMake, Xcode command line tools)
  2. In VSCode, install the "CMake Tools" extension
  3. Follow this guide to set it up: Get started with CMake Tools on Linux. I used the kit "Clang 13.0.0" and the variant "Debug"
  4. Set up your launch.json to use the simulator. The two lines you care about are:
    "program": "/Users/username/Developer/PlaydateSDK/bin/Playdate Simulator.app"
    "args": ["${workspaceFolder}/hello_world.pdx"],
  5. You should be good to go. Use Run -> Start Debugging, watch the Simulator launch your pdx, and your breakpoints will get hit.
4 Likes

I had trouble with this - I'm on an ARM mac (if that makes a difference). Building was ok but using the standard debug target (cppdbg) I think the debugger launches the emulated x86_64 playdate sim (you get a message about target architecuture) and then you can't load the arm64 compiled dylib.

I tried setting targetArchitecture to "arm64" and that makes the message go away but the simulator still fails to load the dylib with a console message that it's a mach.o file but still the wrong architecture.

Possibly if you used an exernal run target instead of a cppdbg it might work, not sure. I do have the CodeLLDB extension installed and running under (the target type is lldb) was much more successful. It also loaded way way faster.

VSCode does look like a pretty good platform for building and running playdate, I still need to get the C stuff configured properly to find header files etc and sort out a workflow I like.

yes confirmed even with the targetArchitecture set the cppdbg command still loads the intel version of the simulator from the bundle so on an M1 mac that doesn't work.

and one more thing - this was actually fixed two days ago in 1.9.3 of the VSCode C++ extension, so if you switch to that pre-release version and set "targetArchitecture":"arm64" it now loads the arm64 version of the simulator, the dylib loads properly and the breakpoints work.

1 Like