Debug
cpbooster
provides a way for you to run your program using your debugging
flags (languages.<lang>.debugCommand
).
You can pass the --debug
flag (or its alias which is just -d
) to the test
command for this.
By default, this command will request keyboard input, just like if you executed ./program.exe
or python program.py
.
If you wish to use a file as input See Debug With Input File.
#
DemoNOTES
- This command will automatically compile your program everytime you run it. See Debug Without Recompiling for details on how to avoid recompiling your program each time.
cpbooster
does not print your debugging lines in red, this should be your code's behavior when running in debug mode. See Debug Tips & Tricks.
#
Executable File DetailsThe executable file will be located in your current directory and its name will
be the concatenation of the source file name and the word "debug" followed by the extension
which will be .exe
. For example, if your source file name is ProblemA.cpp
then the executable file
name will be ProblemAdebug.exe
. This is because cpbooster
uses filenames to associate everything
(See File Structure for better understanding).
If you wish to save the executable file with a different name,
you can specify it in your languages.<lang>.debugCommand
.
#
Debug With Input FileYou can specify a test case to run in debugging mode using the --testId
flag or its alias -t
.
note
The only difference between the command used to Test With A Single Test Case and this one, is the
-d
flag at the end, which tells cpbooster
to run in debug mode.
#
Demo#
Debug Without RecompilingYou can tell cpbooster
to run in debug mode using the last compiled version of your program
by passing the flag --noCompile
or its alias --nc
.
caution
By using this flag, cpbooster
will assume that there is a corresponding executable file
for your program. Remember that the name of the executable file must be the same as the
source file plus the word "debug", followed by the extension which must be .exe
. Unless you specified otherwise
in languages.<lang>.debugCommand
.
#
Debug Tips & Tricks#
Improve RTE Feedback In C++You can use the following debug command to get much better feedback in case of runtime errors.
cpbooster-config.json
#
#
Print Debug Lines In Red In C++cpbooster-config.json
#
program.cpp
#
note
Here we used the -DDEBUG
flag in the debug command and therefore our #ifdef
statement
should check for the existence of DEBUG
. If we had specified a different flag name,
for example, -DHOLA
, then the #ifdef
statement should check the existence of HOLA
.
tip
You can avoid writing #ifdef
every time if you use a well done template like THIS one,
which allows you to use a debug(...)
function that can print anything that you pass to it.
See Print Anything Like In Python With C++.
#
Debug Command In PythonIn Python
you can use the -O
flag to print statements just when this flag is used.
cpbooster-config.json
#
program.py
#
#
Print Anything Like In Python With C++Placing the following code on top of your source file, will enable you
to use a debug(...)
function, which will work almost like the print(...)
function
in python and it will just work if we pass the -DDEBUG
flag
to the compilation command. This function can receive any amount of parameters and
they can be of almost any type, to be strict, it supports all primitive types
(bool, int, char, ...
), all iterable types (vector, map, set, deque, ...
) and some
other types like pair
and tuple
.