--- tags: debug --- # Using Address Sanitizer in VS Code for C Language on Mac ## Running normally in VS Code ![](https://i.imgur.com/CnFWsaV.png) After installing all the essential components for VS Code to complie C language, we can run the code by pressing "control+option+N", VS Code will automatically generate the words `cd "/Users/lintingxuan/Desktop/9/" && gcc main.c -o main && "/Users/lintingxuan/Desktop/9/"main` while `"/Users/lintingxuan/Desktop/9/"` is the directory of this `main.c` file ![](https://i.imgur.com/Hq2Ugwu.png) ## Running Address Sanitizer in VS Code Instead of pressing `"control+option+N"`, we type the words ourselves ``` gcc main.c -o main -fsanitize=address -g && "/Users/lintingxuan/Desktop/9/"main ``` ![](https://i.imgur.com/3N4ZP34.png) After pressing enter, we can see something like ![](https://i.imgur.com/zLIohh5.png) We can type in whatever we want to use as an input of the program, if there is an error, it will show ![](https://i.imgur.com/Uc4JLJR.png) ![](https://i.imgur.com/fsJGLjQ.png) We shall edit our code until the image above does not show, then everything is good. ## Reference 1. [address sanitizer](https://www.osc.edu/resources/getting_started/howto/howto_use_address_sanitizer) 2. [solution for mac](https://stackoverflow.com/questions/44501833/makefile-for-linux-and-mac-with-address-sanitizer) 3. [debug](https://www.youtube.com/watch?v=KMC4AKpq_CM)