Inspect pointer bug in C++
This shows shows how the Memory Inspector can be used to find pointer bugs in C/C++ source code. Note: this only works with the C/C++ DevTools helper extension. See below for instructions to get it.
Steps
- Get the C/C++ DevTools helper extension
- Open DevTools
- Enable the Wasm Debugging Experiment: click the gear icon on the top right corner of DevTools, go to Experiments and tick the WebAssembly Debugging: Enable DWARF support. See this blogpost for more information.
- Reload DevTools as prompted on the banner after closing the settings
- Wait until the
demo-pointer-bug.cc
module shows up
- Locate the function
main
from the demo-pointer-bug.cc
module and set a breakpoint on line 9
- Reload the page
- Inspect the Scope View. The Local Scope shows the static array
numbers
. Inspect it by right clicking on the memory icon next to numbers
- Notice the Memory Inspector automatically highlights all of the bytes corresponding to the inspected
numbers
- Inspect the Scope View. The Local Scope shows the integer pointer
lastNumber
. Inspect it by right clicking on the memory icon next to lastNumber
- Notice the Memory Inspector switches the highlight from
numbers
to lastNumber
and that lastNumber
lies right after the end of numbers