Skip to content

Commit 502c56c

Browse files
TylerMSFTTylerMSFT
authored andcommitted
fix numbering
1 parent d4007c3 commit 502c56c

File tree

1 file changed

+59
-59
lines changed

1 file changed

+59
-59
lines changed

docs/sanitizers/asan.md

Lines changed: 59 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -144,82 +144,82 @@ To build and run the debugger, press **F5**. An **Exception Thrown** window appe
144144

145145
## <a name="ide-cmake"></a> Use AddressSanitizer from Visual Studio: CMake
146146

147-
To enable AddressSanitizer for a [CMake project created to target Windows](../build/cmake-projects-in-visual-studio.md), take these steps:
147+
To enable AddressSanitizer for a [CMake project created to target Windows](../build/cmake-projects-in-visual-studio.md), follow these steps:
148148

149149
1. Open the **Configurations** dropdown in the toolbar at the top of the IDE and select **Manage Configurations**.
150150

151-
:::image type="content" source="media/asan-cmake-configuration-dropdown.png" alt-text="Screenshot of the CMake configuration dropdown.":::
151+
:::image type="content" source="media/asan-cmake-configuration-dropdown.png" alt-text="Screenshot of the CMake configuration dropdown. It displays options like x64 Debug, x64 Release, and so on. At the bottom of the list, Manage Configurations... is highlighted.":::
152152

153-
That selection opens the CMake Project Settings editor, which reflects the contents of the `CMakeSettings.json` file in your project.
153+
That opens the CMake Project Settings editor, which reflects the contents of your project's `CMakeSettings.json` file.
154154

155155
1. Choose the **Edit JSON** link in the editor. This selection switches the view to raw JSON.
156156

157157
1. Add the following snippet to the `"windows-base"` preset, inside `"configurePresets":` to turn on Address Sanitizer:
158158

159-
```json
160-
"environment": {
161-
"CFLAGS": "/fsanitize=address",
162-
"CXXFLAGS": "/fsanitize=address"
163-
}
164-
```
165-
166-
It looks something like this, afterwards:
167-
168-
```json
169-
"configurePresets": [
170-
{
171-
"name": "windows-base",
172-
"hidden": true,
173-
"generator": "Ninja",
174-
"binaryDir": "${sourceDir}/out/build/${presetName}",
175-
"installDir": "${sourceDir}/out/install/${presetName}",
176-
"cacheVariables": {
177-
"CMAKE_C_COMPILER": "cl.exe",
178-
"CMAKE_CXX_COMPILER": "cl.exe"
179-
},
180-
"condition": {
181-
"type": "equals",
182-
"lhs": "${hostSystemName}",
183-
"rhs": "Windows"
184-
},
185-
"environment": {
186-
"CFLAGS": "/fsanitize=address",
187-
"CXXFLAGS": "/fsanitize=address"
188-
}
189-
},
190-
```
159+
```json
160+
"environment": {
161+
"CFLAGS": "/fsanitize=address",
162+
"CXXFLAGS": "/fsanitize=address"
163+
}
164+
```
165+
166+
`"configurePresets"` looks something like this, afterwards:
167+
168+
```json
169+
"configurePresets": [
170+
{
171+
"name": "windows-base",
172+
"hidden": true,
173+
"generator": "Ninja",
174+
"binaryDir": "${sourceDir}/out/build/${presetName}",
175+
"installDir": "${sourceDir}/out/install/${presetName}",
176+
"cacheVariables": {
177+
"CMAKE_C_COMPILER": "cl.exe",
178+
"CMAKE_CXX_COMPILER": "cl.exe"
179+
},
180+
"condition": {
181+
"type": "equals",
182+
"lhs": "${hostSystemName}",
183+
"rhs": "Windows"
184+
},
185+
"environment": {
186+
"CFLAGS": "/fsanitize=address",
187+
"CXXFLAGS": "/fsanitize=address"
188+
}
189+
},
190+
```
191191

192192
1. Address sanitizer doesn't work if edit-and-continue is specified (`/ZI`), which is enabled by default for new CMake projects. In `CMakeLists.txt`, comment out (prefix with `#`) the line that starts with `set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT"`. That line looks something like this, afterwards:
193193

194-
```json
195-
# set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$<IF:$<AND:$<C_COMPILER_ID:MSVC>,$<CXX_COMPILER_ID:MSVC>>,$<$<CONFIG:Debug,RelWithDebInfo>:EditAndContinue>,$<$<CONFIG:Debug,RelWithDebInfo>:ProgramDatabase>>")
196-
```
194+
```json
195+
# set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$<IF:$<AND:$<C_COMPILER_ID:MSVC>,$<CXX_COMPILER_ID:MSVC>>,$<$<CONFIG:Debug,RelWithDebInfo>:EditAndContinue>,$<$<CONFIG:Debug,RelWithDebInfo>:ProgramDatabase>>")
196+
```
197197

198198
1. Enter **Ctrl+S** to save this JSON file
199-
1. Clear your CMake cache directory and reconfigure: choose **Project** > **Delete cache and Reconfigure**. Choose **Yes** when the prompt appears to clear your cache directory and reconfigure.
200-
1. Replace the contents of the cpp file (for example, `CMakeProject1.cpp`) with the following:
201-
202-
```cpp
203-
// CMakeProject1.cpp : Defines the entry point for the application
204-
205-
#include <stdio.h>
206-
207-
int x[100];
208-
209-
int main()
210-
{
211-
printf("Hello!\n");
212-
x[100] = 5; // Boom!
213-
return 0;
214-
}
215-
```
199+
1. Clear your CMake cache directory and reconfigure by choosing from the Visual Studio menu: **Project** > **Delete cache and Reconfigure**. Choose **Yes** when the prompt appears to clear your cache directory and reconfigure.
200+
1. Replace the contents of the source file (for example, `CMakeProject1.cpp`) with the following:
201+
202+
```cpp
203+
// CMakeProject1.cpp : Defines the entry point for the application
204+
205+
#include <stdio.h>
206+
207+
int x[100];
208+
209+
int main()
210+
{
211+
printf("Hello!\n");
212+
x[100] = 5; // Boom!
213+
return 0;
214+
}
215+
```
216216

217217
1. Choose **F5** to recompile and run under the debugger.
218218

219-
This screenshot captures the error from the CMake build.
220-
221-
:::image type="content" source="media/asan-cmake-error-f5.png" alt-text="Screenshot of an exception that says: Address Sanitizer Error: Global buffer overflow. In the background, address sanitizer output is visible in command window":::
222-
219+
This screenshot captures the error from the CMake build.
220+
221+
:::image type="content" source="media/asan-cmake-error-f5.png" alt-text="Screenshot of an exception that says: Address Sanitizer Error: Global buffer overflow. In the background, address sanitizer output is visible in command window":::
222+
223223
## <a name="crash-dumps"></a> AddressSanitizer crash dumps
224224

225225
We introduced new functionality in AddressSanitizer for use with cloud and distributed workflows. This functionality allows offline viewing of an AddressSanitizer error in the IDE. The error gets overlaid on top of your source, just as you would experience in a live debug session.

0 commit comments

Comments
 (0)