This repository has been archived on 2022-06-22. You can view files and clone it, but cannot push or open issues or pull requests.
usaco-guide/content/2_General/6_Debugging.md
2020-06-08 20:47:37 -04:00

1.3 KiB

slug title author order
/general/debugging Debugging Benjamin Qi 6

Compilation

I use the following command:

g++ -std=c++11 -O2 -o $1 $1.cpp -Wall -Wextra -Wshadow -DLOCAL -Wl,-stack_size -Wl,0xF0000000;

Warnings

See here.

-Wall -Wextra -Wshadow

Stack Size

According to this comment, -Wl,-stack_size -Wl,0xF0000000 increases the stack size on Mac (otherwise, you might get RTE).

(Documentation?)

Other

-fsanitize=undefined -fsanitize=address

-D_GLIBCXX_DEBUG -g

(someone want to explain these? I don't use)

Printing

Although not feasible if you have to write all code from scratch, I find this very helpful. dbg() only produces output when -DLOCAL is included as part of the compilation command.

(add examples of usage)

Stress Testing

You can use a simple script to test two solutions against each other. See Errichto's video on testing solutions for more information.

Debugger

Ok I don't actually know how to use ... (someone else want to add?)