Inspecting memory in zxdb

Zxdb supports the following commands for inspecting memory:

aspace: Show mapped memory regions.

The aspace command, abbreviated as, outputs address space information for the process. In Fuchsia, virtual memory consists of a hierarchy of Virtual Memory Objects (VMOs).

With no parameters, the aspace command shows all VMOs in the process.

```none {:.devsite-disable-click-to-copy} [zxdb] as

  1. When given an address, the `aspace` command shows the VMO hierarchy containing just that address.
  2. This can be useful to determine where an address is in memory, as the names of the VMOs typically
  3. indicate what type of region that is.
  4. ```none {:.devsite-disable-click-to-copy}
  5. [zxdb] as 0x10b7f304d28

Understanding the output

In the following example, the aspace command details the following about the 0x10b7f304d28 address:

  • Hierarchy of VMOs that contain the address.
  • The address and size of each VMO.
  • The name of each VMO, which can give clues about their purpose.
    • From the name in this example, you can tell the address is in a stack allocated by pthreads.

```none {:.devsite-disable-click-to-copy} Start End Size Name 0x1000000 0x7ffffffff000 127T proc:3109 0x1000000 0x7ffffffff000 127T root 0x10b7f104000 0x10b7f305000 2M useralloc 0x10b7f105000 0x10b7f305000 2M pthread_t:0x10c4ea38b00

  1. The following are relevant VMO names that could be included in output from the `aspace` command:
  2. * `initial-thread`: The stack of the startup thread.
  3. * `pthread_t:0x...`: The stack of a pthread-created thread. The address indicates the memory
  4. location of the `pthread_t structure for that thread.
  5. * `*uncompressed-bootfs`: A memory-mapped library coming from bootfs (core system libraries). The
  6. `libs` command can tell you the library name for that address.
  7. * `stack: msg of ...`: The startup stack. This very small stack is used only by the dynamic linker
  8. and loader code.
  9. * `scudo:*`: Pages allocated with the scudo memory manager. If the process is using scudo, these
  10. regions are the application heap.
  11. * `vdso/full`: The built-in library that implements system calls.
  12. * `blob-*`: Mapped library coming from blobfs. The `libs` command can tell you the library name
  13. for that address.
  14. ## `mem-analyze`: Dumps memory, trying to interpret pointers.
  15. This command attempts to interpret memory as pointers and decode what they point to. Addresses with
  16. corresponding symbols are symbolized, while other addresses indicate the name of the
  17. memory-mapping region they fall into (see the [`aspace`](#aspace_show_mapped_memory_regions)
  18. command). It can be useful for dumping unknown memory.
  19. ```none {:.devsite-disable-click-to-copy}
  20. [zxdb] ma 0x42ff9c2fdd30
  21. Address Data
  22. 0x42ff9c2fdd30 0x00000000000015f0
  23. 0x42ff9c2fdd38 0x0000000000000008
  24. 0x42ff9c2fdd40 0x000042f401a8a730 ldso
  25. 0x42ff9c2fdd48 0x000042f401a8a9f8 $(dls3.app)
  26. 0x42ff9c2fdd50 0x0000000000000053
  27. 0x42ff9c2fdd58 0x0000000010469c6b
  28. 0x42ff9c2fdd60 0x000042f401a8a9f8 $(dls3.app)
  29. 0x42ff9c2fdd68 0x0000000000000000
  30. 0x42ff9c2fdd70 0x000042ff9c2fde70 inside map "stack: msg of 0x1000"
  31. 0x42ff9c2fdd78 0x000042f4015e5548 dls3 + 0x42b
  32. 0x42ff9c2fdd80 0x10469c6b10769c7b
  33. 0x42ff9c2fdd88 0x10569c3310469c23
  34. 0x42ff9c2fdd90 0x10469c2710469c37

See also stack, which is a variant of the mem-analyze command for stack analysis.

mem-read: Dump process memory

The mem-read command, abbreviated x, provides hex dumps of the given address. You supply the address and optionally override the default size with the -s option.

```none {:.devsite-disable-click-to-copy} [zxdb] x -s 100 0x42ff9c2fdd30 0x42ff9c2fdd30: f0 15 00 00 00 00 00 00-08 00 00 00 00 00 00 00 | 0x42ff9c2fdd40: 30 a7 a8 01 f4 42 00 00-f8 a9 a8 01 f4 42 00 00 |0 B B 0x42ff9c2fdd50: 53 00 00 00 00 00 00 00-6b 9c 46 10 00 00 00 00 |S k F 0x42ff9c2fdd60: f8 a9 a8 01 f4 42 00 00-00 00 00 00 00 00 00 00 | B 0x42ff9c2fdd70: 70 de 2f 9c ff 42 00 00-48 55 5e 01 f4 42 00 00 |p / B HU^ B 0x42ff9c2fdd80: 7b 9c 76 10 6b 9c 46 10-23 9c 46 10 33 9c 56 10 |{ v k F # F 3 V 0x42ff9c2fdd90: 37 9c 46 10

  1. You can also supply an expression that evaluates to an address. If the type of the pointer has
  2. a known size, the dump automatically shows that many bytes:
  3. ```none {:.devsite-disable-click-to-copy}
  4. [zxdb] x &self->main_waker
  5. 0x1605a5d1ed0: 70 1a c8 36 47 04 00 00-68 fe 3d dd 25 01 00 00 |p 6G h = %

stack: Provides a low-level analysis of the stack

The stack command analyzes the stack in a similar way to mem-analyze. It defaults to the top of the current thread’s stack. The stack command attempts to decode addresses present in the memory region, but it also adds annotations for the known register values and stack base pointers of the thread.

```none {:.devsite-disable-click-to-copy} [zxdb] stack Address Data 0x1605a5d1428 0x000042a352fca11f ◁ rsp. ▷ _zx_port_wait + 0x1f 0x1605a5d1430 0x000001605a5d1460 ◁ frame 1 rsp. ▷ inside map “initial-thread” 0x1605a5d1438 0x000001605a5d1540 ▷ inside map “initial-thread” 0x1605a5d1440 0x7fffffffffffffff 0x1605a5d1448 0x0000044ab6c81800 ▷ inside map “scudo:primary” 0x1605a5d1450 0x000001605a5d14d0 ◁ rbp, frame 1 base. ▷ inside map “initial-thread” 0x1605a5d1458 0x00000125dd3566f5 ▷ fuchsia_zircon_status::Status::ok 0x1605a5d1460 0x0000000000000000 ◁ frame 2 rsp 0x1605a5d1468 0x0000000000000000 0x1605a5d1470 0x0000000000000000 0x1605a5d1478 0x0000000000000000 0x1605a5d1480 0x0000000000000000 ◁ rdx, r14

  1. In the notes colum, left-pointing arrows indicate which registers point to that stack location,
  2. while right-pointing arrows indicate where the value of the stack entry points to if it is
  3. interpreted as an address.
  4. ## `sym-near`: Map addresses to symbols
  5. The `sym-near` command, abbreviated `sn`, attempts to map an address to a symbol name. Running the
  6. command outputs the name and line information (if available) for the symbol at or preceeding the
  7. address and is most often used to tell what a pointer points to.
  8. ```none {:.devsite-disable-click-to-copy}
  9. [zxdb] sym-near 0x125dd3a845e
  10. 0x125dd3a845e, power_manager::main() • main.rs:37