Hardware-Assisted Address Sanitizer (HWASan) is a memory error detection tool similar to ASan. Compared with ASan, HWASan uses significantly less memory, making it more suitable for system-wide sanitization. For details about the HWASan detection principles, see HWASan Detection Principles.
For versions earlier than DevEco Studio 6.1.0 Beta1, HWASan can be enabled only for C++ source code.
Since DevEco Studio 6.1.0 Beta1, binary instrumentation is supported for .so files generated from C++ compilation without source code, enabling HWASan.
Since DevEco Studio 6.1.0 Beta1, you can also select BinXO check to enable HWASan instrumentation for .so files without source code.

"buildOption": {
"nativeLib": {
"excludeSoFromBinXO": ["**/liblibrary.so"]
}
} "hwasanEnabled": true

// For versions earlier than DevEco Studio 6.1.0 Beta1
"buildOption": {
"externalNativeOptions": {
"arguments": ["-DOHOS_ENABLE_HWASAN=ON"]
}
// For DevEco Studio 6.1.0 Beta1 and later versions, enable HWASan instrumentation for both C++ files with and without source code.
"buildOption": {
"externalNativeOptions": {
"arguments": ["-DOHOS_ENABLE_HWASAN=ON", "-DOHOS_ENABLE_BINXO=ON"]
} "buildOption": {
"nativeLib": {
"excludeSoFromBinXO": ["**/liblibrary.so"]
}
} Since version 26.0.0, the pseudocode, method parameters, and names and values of variables corresponding to the error stack can be parsed. Only the first three stack frames (#0 to #2) are parsed. For frame #0, the input parameters, variable names, and variable values are parsed. For frames #1 and #2, only the input parameters and variable names are parsed.
To ensure correct stack trace parsing, debug information must be retained in the code. For details, see Precautions.


To ensure correct stack trace parsing, debug information must be retained in the code. To achieve this, perform the steps below.
"nativeLib": {
"debugSymbol": {
"strip": false
}
} set_source_files_properties(
filename.cpp
PROPERTIES COMPILE_FLAGS "-O0"
)
string(REPLACE "-O2" "-O0"
CMAKE_CXX_FLAGS_RELEASE
"${CMAKE_CXX_FLAGS_RELEASE}"
)
string(REPLACE "-O2" "-O0"
CMAKE_C_FLAGS_RELEASE
"${CMAKE_C_FLAGS_RELEASE}"
)