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

  1. Get the C/C++ DevTools helper extension
  2. Open DevTools
  3. 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.
  4. Reload DevTools as prompted on the banner after closing the settings
  5. Wait until the demo-pointer-bug.cc module shows up
  6. Locate the function main from the demo-pointer-bug.cc module and set a breakpoint on line 9
  7. Reload the page
  8. Inspect the Scope View. The Local Scope shows the static array numbers. Inspect it by right clicking on the memory icon next to numbers
  9. Notice the Memory Inspector automatically highlights all of the bytes corresponding to the inspected numbers
  10. Inspect the Scope View. The Local Scope shows the integer pointer lastNumber. Inspect it by right clicking on the memory icon next to lastNumber
  11. Notice the Memory Inspector switches the highlight from numbers to lastNumber and that lastNumber lies right after the end of numbers