Memory Inspector: Inspect ArrayBuffer, TypedArray, DataView, and Wasm Memory.

Sofia Emelianova
Sofia Emelianova

Use the Memory inspector to inspect ArrayBuffer, TypedArray, and DataView memory in JavaScript as well as WebAssembly.Memory of Wasm applications written in C++.

Overview

The Memory inspector organizes memory content and helps you navigate large arrays quickly. You can view the ASCII values of memory content directly next to the bytes, and select different endianness. Use the Memory inspector while you debug your web app for an efficient workflow.

Open the Memory Inspector

There are a few ways to open the Memory inspector.

Open from the menu

  1. Open DevTools.
  2. Click More Options More > More tools > Memory inspector. Memory inspector menu

Open during debugging

  1. Open a page with JavaScript ArrayBuffer. We will be using this demo page.
  2. Open DevTools.
  3. Open the demo-js.js file in the Sources panel, set a breakpoint at line 18.
  4. Refresh the page.
  5. Expand the Scope section on the right Debugger pane.
  6. You can open the Memory 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 select Reveal in Memory Inspector panel.

    Reveal in Memory Inspector panel

Inspect multiple objects

  1. You can inspect DataView or TypedArray as well. For example, b2 is a TypedArray. To inspect that, right click on the b2 property and select Reveal in Memory Inspector panel (No icon for TypedArray or DataView yet).
  2. A new tab is opened in the Memory inspector. Please note that you can inspect multiple objects at once. New tab in the Memory inspector

The Memory inspector

The Memory inspector

The Memory inspector consists of 3 main areas:

Navigation bar

  1. The address input shows 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.
  2. Memory buffers could be longer than a page. Instead of scrolling through, you can use the left and right button to navigate.
  3. The buttons on the left allow a forward/backward navigation.
  4. By default, the buffer is automatically updated on stepping. In the case it's not, the refresh button gives you the option to refresh the memory and update its contents.

Memory buffer

Memory buffer

  1. From the left, the address is displayed in hex format.
  2. The memory is 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).
  3. An ASCII representation of 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

Value inspector

  1. A top toolbar features a button to switch between big and little endian and to open the settings. Open the settings to select which value types they want to see per default in the inspector. toolbar button
  2. The main area shows all the value interpretations as per the settings. By default, all are shown.
  3. The encoding is clickable. You can switch between dec, hex, oct for integer and sci, dec for floats. Encoding switch

Inspecting memory

Let's inspect the memory together.

  1. Follow these steps to start the debugging.
  2. Change the address to 0x00000027 in the address input. address input
  3. Observe the ASCII representation and the value interpretations. All values are empty at the moment.
  4. Notice the blue Jump to address button next to Pointer 32-bit and Pointer 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. Jump to address button
  5. Click on Resume script execution to step through the code. Resume script execution
  6. Notice the ASCII representation is now updated. All the value interpretations are updated as well. All value interpretations are updated
  7. Let's customize the Value inspector to show only floating point. Click on the settings button and check only Float 32-bit and Float 64-bit. settings to customize value inspector
  8. Let's change the encoding from dec to sci. Notice the value representations are updated accordingly. Change the encoding.
  9. Try to navigate the memory buffer with your keyboard or using the navigation bar. Repeat step 4 to observe values changes.

WebAssembly memory inspection

The WebAssembly.Memory object is an ArrayBuffer that holds the raw bytes of object memory. The Memory Inspector panel lets you inspect such objects in Wasm applications written in C++.

To take full advantage of WebAssembly.Memory inspection:

  • Use Chrome 107 or later. Check your version at chrome://version/.
  • Install the C/C++ DevTools Support (DWARF) extension. This is a plugin for debugging C/C++ WebAssembly applications using DWARF debug information.

To inspect the WebAssembly.Memory of an object:

  1. Open DevTools on this demo page.
  2. In the Sources panel, open demo-cpp.cc and set a breakpoint in the main() function at line 15: x[i] = n - i - 1;.
  3. Reload the page to run the application. The debugger pauses at the breakpoint.
  4. In the Debugger pane, expand Scope > Local.
  5. Click the Reveal in Memory Inspector. icon next to the x: int[10] array.

    Alternatively, right-click the array and select Reveal in Memory Inspector panel.

The x array opened in Memory Inspector.

To stop highlighting object memory, in the Memory Inspector panel, hover over the object badge and click the x button.

Stop highlighting object memory.

To learn more, see: