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

47 lines
1.3 KiB
Markdown
Raw Normal View History

2020-06-08 20:42:55 +00:00
---
slug: /general/debugging
title: Debugging
2020-06-09 00:47:37 +00:00
author: Benjamin Qi
2020-06-08 20:42:55 +00:00
order: 6
---
2020-06-09 00:47:37 +00:00
## Compilation
2020-06-08 19:51:58 +00:00
2020-06-09 00:47:37 +00:00
I use the following command:
2020-06-08 19:51:58 +00:00
2020-06-09 00:47:37 +00:00
`g++ -std=c++11 -O2 -o $1 $1.cpp -Wall -Wextra -Wshadow -DLOCAL -Wl,-stack_size -Wl,0xF0000000;`
2020-06-08 19:51:58 +00:00
2020-06-09 00:47:37 +00:00
### Warnings
See [here](https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html).
`-Wall -Wextra -Wshadow`
### Stack Size
According to [this comment](https://codeforces.com/blog/entry/60999?#comment-449312), `-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](https://github.com/bqi343/USACO/blob/master/Implementations/content/contest/CppIO.h) 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](https://github.com/bqi343/USACO/blob/master/Implementations/content/contest/stress.sh) to test two solutions against each other. See Errichto's [video](https://www.youtube.com/watch?v=JXTVOyQpSGM) on testing solutions for more information.
## Debugger
Ok I don't actually know how to use ... (someone else want to add?)