DEBUG Annotations

This isn't working. In VSC at least, the (:debug) function is called regardless of running it with Start Debugging or not.

Is there a way to select in VSC if I run my code with the debug or release code blocks?

My desire is to compile a release edition with a smaller memory footprint, but run with the debug blocks in VSC when needed.

  • These are two different things. The "Start debugging" and "Run without debugging" means compiling the program, loading and running it in the simulator and then either have a debugger attached or not. If you decide to run it in a debug session, you can set breakpoints which eventually get triggered so you can inspect your program step by step for example.

    The (:debug) and (:release) annotations mean which code block gets compiled into the program binary depending on if you compile with the -r (or --release) flag or not. Compiling with the -r flag is necessary to build an .iq file that you can upload to the IQ store. So in short: Code with the (:debug) annotation will not be part of your .iq file and is exactly what you are looking for.

  • There are release builds and debug builds.  The debug builds include the symbols and the prg fil will be much bigger.  When you build for the sim, that's a debug build.  When you build an iq, those are release builds.

    When you use "build for device" you can select a debug or release build.

    This annotation is looking for a debug build vs a release build.

  • Thanks! That is GREAT. I can remove (:debug) code for release when I compile/build the .iq file for EXPORT using the -r flag. But in the sim it'll always use the (:debug) versions. There could be, I suppose, code path / logic issues with the debug code removed... so is there any way to tell the simulator to execute the "release" version - using (:release) annotations?

  • Thanks! That is GREAT. I can remove (:debug) code for release when I compile/build the .iq file for EXPORT using the -r flag. But in the sim it'll always use the (:debug) versions. There could be, I suppose, code path / logic issues with the debug code removed... so is there any way to tell the simulator to execute the "release" version - using (:release) annotations?

    You haven't fully understood the comment you're replying to.

    The -r flag is set automatically when your export your project to an IQ file. You don't have any say in the matter, it will happen no matter what you do. This is something that you would easily be able to see for yourself if you just look at the terminal window when you export a CIQ project.

    You actually *cannot* build the debug version of your code when you export the project, as far as I know. (Unless you were to reverse-engineer the export procedure and run the individual steps yourself)

    so is there any way to tell the simulator to execute the "release" version - using (:release) annotations?

    You also haven't understood that the simulator simply executes what was built with the Monkey C: Build Current Project command. (If you run a project that has source code changes, the extension runs Build Current Project automatically.)

    It's not a matter of 2 versions (release and debug) being built side-by-side and the simulator choosing to run one or the other, as you are implying here and in the OP. Build Current Project (which builds for the simulator, if you are following along), only ever builds one PRG, and by default, it builds the debug version of your app.

    Have you ever looked in the bin\ folder of your project and noticed that it *doesn't* contain 2 PRGs at the same time, but only ever 1 PRG (unless you change your project name)? This is something that you could also have easily checked for yourself. How would the simulator choose between 2 hypothetical PRGs (debug and release) when there's only ever 1 PRG in the bin folder? Have you noticed that if there's no source code changes, the PRG *doesn't* get rebuilt when you run your project in the sim?

    What needs to happen is you need to build the release version, and that's what will be run by the sim. Again, the sim just runs whatever you build. It doesn't know or care whether it's running the debug or release version of your code. I don't think you understood this nuance.

    The simple solution to run the release version of your code in the sim is to temporarily add the "-r" flag to the compiler options. It's very strange that you mentioned you would do this for exporting a project (even though it's not necessary and has no effect), yet you completely missed the hint that you should do this for building a project normally, if you want to test your release code in the sim.

    To be clear:

    - CTRL-SHIFT-P > User Settings

    - Add "-r" to Monkey C: Compiler Options

    Since you already had the idea of using "-r" flag (but only for exporting), again this is something you could have easily tried for yourself, based on the hints that were already given. It's literally the same idea that you already had for exporting the project, but applied to running it in the sim.

    Unless of course you had a stubborn assumption that there's absolutely nothing you can do to prevent the sim from running the debug version, in which case why would you be asking how to do it?

  • TL;DR just add "-r" to the compiler options if you want to test the release version in the sim. The very first reply basically says so, and you yourself had the exact same idea, except only for exporting the project (where it isn't even necessary).

  • I'm not with computer, so I can't post is, but a more user friendly way is to have a launch.json file and then you can choose from VSC which build you want to run in the simulator. Try to search the forum, I think there are usable examples, if you can't find, I'll post it on Sunday