Use the newMemory inspectorto inspectArrayBuffer
,TypedArray
,andDataView
memory in JavaScript as well asWebAssembly.Memory
of Wasm applications written in C++.
Open the Memory Inspector
There are a few ways to open theMemory inspector.
Open from the menu
- Open DevTools.
- ClickMore Options>More tools>Memory inspector.
Open during debugging
- Open a page with JavaScript
ArrayBuffer
.We will be usingthis demo page. - Open DevTools.
- Open thedemo-js.jsfile in theSourcespanel, set a breakpoint at line 18.
- Refresh the page.
- Expand theScopesection on the rightDebuggerpane.
You can open theMemory inspector:
- From the icon.Clicking on the icon next to the
buffer
property, or - From the context menu.Right click on the
buffer
property and selectReveal in Memory Inspector panel.
- From the icon.Clicking on the icon next to the
Inspect multiple objects
- You can inspectDataVieworTypedArrayas well. For example,
b2
is aTypedArray
.To inspect that, right click on theb2
property and selectReveal in Memory Inspector panel(No icon forTypedArray
orDataView
yet). - A new tab is opened in theMemory inspector.Please note that you can inspect multiple objects at once.
The Memory inspector
TheMemory inspectorconsists of 3 main areas:
Navigation bar
- Theaddress inputshows the current byte address in hex format. You can input a new value to jump to a new location in the memory buffer. For example, try type
0x00000008
. - Memory buffers could be longer than a page. Instead of scrolling through, you can use theleftandrightbutton to navigate.
- The buttons on the left allow aforward/backwardnavigation.
- By default, the buffer is automatically updated on stepping. In the case it's not, therefreshbutton gives you the option to refresh the memory and update its contents.
Memory buffer
- From the left, theaddressis displayed in hex format.
- Thememoryis also shown in hex format, each byte separated by a space. The currently selected byte is highlighted. You can click on the byte or navigate with keyboard (left, right, up, down).
- AnASCII representationof the memory is shown on the right side. A highlight shows the corresponding value to the selected bits on the byte. Similar to memory, you can click on the byte or navigate with keyboard (left, right, up, down).
Value inspector
- A top toolbar features a button to switch betweenbig and little endianand to open thesettings.Open thesettingsto select which value types they want to see per default in the inspector.
- The main area shows all thevalue interpretationsas per thesettings.By default, all are shown.
- Theencodingis clickable. You can switch between dec, hex, oct for integer and sci, dec for floats.
Inspecting memory
Let's inspect the memory together.
- Follow these steps tostartthe debugging.
- Change the address to
0x00000027
in theaddress input. - Observe theASCII representationand thevalue interpretations.All values are empty at the moment.
- Notice the blueJump to addressbutton next to
Pointer 32-bit
andPointer 64-bit
.You can click on it to jump to the address. The buttons are grayed out and not clickable if the addresses are not valid. - Click onResume script executionto step through the code.
- Notice theASCII representationis now updated. All thevalue interpretationsare updated as well.
- Let's customize theValue inspectorto show onlyfloating point.Click on thesettingsbutton and check onlyFloat 32-bitandFloat 64-bit.
- Let's change the encoding from
dec
tosci
.Notice the value representations are updated accordingly. - Try to navigate the memory buffer with your keyboard or using the navigation bar. Repeat step 4 to observe values changes.
WebAssembly memory inspection
TheWebAssembly.Memory
object is anArrayBuffer
that holds the raw bytes of object memory. TheMemory Inspectorpanel lets you inspect such objects in Wasm applications written in C++.
To take full advantage ofWebAssembly.Memory
inspection:
- Use Chrome 107 or later. Check your version at
chrome://version/
. - Install theC/C++ DevTools Support (DWARF)extension. This is a plugin for debugging C/C++ WebAssembly applications using DWARF debug information.
To inspect theWebAssembly.Memory
of an object:
- Open DevToolsonthis demo page.
- In theSourcespanel, open
demo-cpp.cc
andset a breakpointin themain()
function at line 15:x[i] = n - i - 1;
. - Reload the page to run the application. The debugger pauses at the breakpoint.
- In theDebuggerpane, expandScope>Local.
Click theicon next to the
x: int[10]
array.Alternatively, right-click the array and selectReveal in Memory Inspector panel.
To stop highlighting object memory, in theMemory Inspectorpanel, hover over the object badge and click thex
button.
To learn more, see: