This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Add --all option to "memory region"
ClosedPublic

Authored by DavidSpickett on Oct 14 2021, 4:50 AM.

Details

Summary

This adds an option to the memory region command
to print all regions at once. Like you can do by
starting at address 0 and repeating the command
manually.

memory region [-a] [<address-expression>]

(lldb) memory region --all
[0x0000000000000000-0x0000000000400000) ---
[0x0000000000400000-0x0000000000401000) r-x <...>/a.out PT_LOAD[0]
<...>
[0x0000fffffffdf000-0x0001000000000000) rw- [stack]
[0x0001000000000000-0xffffffffffffffff) ---

The output matches exactly what you'd get from
repeating the command. Including that it shows
unmapped areas between the mapped regions.

(this is why Process GetMemoryRegions is not
used, that skips unmapped areas)

Help text has been updated to show that you can have
an address or --all but not both.

Diff Detail

Event Timeline

DavidSpickett created this revision.Oct 14 2021, 4:50 AM
DavidSpickett requested review of this revision.Oct 14 2021, 4:50 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 14 2021, 4:50 AM

Correct help text. Make a parameter const (uses the previous stacked change).

Herald added a project: Restricted Project. · View Herald TranscriptMay 17 2022, 6:55 AM

Figured that the usage was now a bit confusing. Though I'm not sure how to write "either" in symbols,
I see {A|B} used in some other tools, I've just stuck with the word "or" for now.

Doesn't matter too much, the usage shown isn't meant to be exhaustive and you have help to give you that.

JDevlieghere accepted this revision.May 17 2022, 8:55 AM

Minor nit but LGTM

lldb/source/Commands/CommandObjectMemory.cpp
1707

Can we move this down, closer to where it's being used?

This revision is now accepted and ready to land.May 17 2022, 8:55 AM

Move variables closer to usage in DumpRegion.

DavidSpickett marked an inline comment as done.May 17 2022, 9:10 AM

Add a release note before I inevitably forget.

Herald added a project: Restricted Project. · View Herald TranscriptMay 17 2022, 9:15 AM

Fixup the tagged memory region test (it doesn't care about the
content of the usage just that the command eventually fails) and rebase.

Fixup the loop on systems that have more non-address bits than just top byte ignore.

With only top byte ignore:

  • We ask the remote for the last region
  • It says ok it's unmapped and it ends at 0xF....F
  • Then we mask that address using just the top byte ignore but because the PAC sign bit is set we actually or in the mask which keeps all the bits set.
  • We ask for a region at LLDB_INVALID_ADDRESS which fails and we break.

With top byte ignore plus pointer auth:

  • We ask for the last region
  • It returns a range with end address 0x0001000000000000
  • Then we ask for the next region
  • Which masks that address with 0xFFFF0...0 and gets 0
  • Which gives you the first region and we loop forever

This is the same thing I did to fix the manual command repetition but
because we got away without it on a TBI only system I didn't notice it
until now.

I figured it needed the same fix but took a bit to figure out why.

This revision was landed with ongoing or failed builds.May 18 2022, 3:33 AM
This revision was automatically updated to reflect the committed changes.