This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Add option to show memory tags in memory read output
ClosedPublic

Authored by DavidSpickett on Jul 30 2021, 2:25 AM.

Details

Summary

This adds an option --show-tags to "memory read".

(lldb) memory read mte_buf mte_buf+32 -f "x" -s8 --show-tags
0x900fffff7ff8000: 0x0000000000000000 0x0000000000000000 (tag: 0x0)
0x900fffff7ff8010: 0x0000000000000000 0x0000000000000000 (tag: 0x1)

Tags are printed on the end of each line, if that
line has any tags associated with it. Meaning that
untagged memory output is unchanged.

Tags are printed based on the granule(s) of memory that
a line covers. So you may have lines with 1 tag, with many
tags, no tags or partially tagged lines.

In the case of partially tagged lines, untagged granules
will show "<no tag>" so that the ordering is obvious.
For example, a line that covers 2 granules where the first
is not tagged:

(lldb) memory read mte_buf-16 mte_buf+16 -l32 -f"x" --show-tags
0x900fffff7ff7ff0: 0x00000000 <...> (tags: <no tag> 0x0)

Untagged lines will just not have the "(tags: ..." at all.
Though they may be part of a larger output that does have
some tagged lines.

To do this I've extended DumpDataExtractor to also print
memory tags where it has a valid execution context and
is asked to print them.

There are no special alignment requirements, simply
use "memory read" as usual. All alignment is handled
in DumpDataExtractor.

We use MakeTaggedRanges to find all the tagged memory
in the current dump, then read all that into a MemoryTagMap.

The tag map is populated once in DumpDataExtractor and re-used
for each subsequently printed line (or recursive call of
DumpDataExtractor, which some formats do).

Diff Detail

Event Timeline

DavidSpickett created this revision.Jul 30 2021, 2:25 AM
DavidSpickett requested review of this revision.Jul 30 2021, 2:25 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 30 2021, 2:25 AM
DavidSpickett added a subscriber: pcc.

DumpDataExtractor has formatting unittests. Due to memory tags being read from the execution context there are no new unittests. (the existing ones pass)

Also since this code isn't exactly simple and could have issues, and tags will be right most of the time I think an opt in to this feature makes sense. I haven't added that here yet but will do if you agree. Not yet sure if it would be an option to "memory read", or a debugger setting.

@pcc We talked about tag formatting in an earlier patch. Your feedback on the format I've gone with would be great.

Also Omair we talked about 13 backports to get MTE support to a good place. This is one that I think would be ok to not do so, given that tag reading can be done manually as needed and it has some complexity to be considered.

Added a command option for showing tags (off by default).

Split the patch into three (see parent revisions).

DavidSpickett retitled this revision from [lldb] Show memory tags in memory read output to [lldb] Add option to show memory tags in memory read output.Oct 29 2021, 8:40 AM
DavidSpickett edited the summary of this revision. (Show Details)

Rebase after changes to previous patches.

Added a release note for the new option/feature.

Herald added a project: Restricted Project. · View Herald TranscriptDec 16 2021, 2:43 AM

Update with changes to previous patches.

omjavaid accepted this revision.Jan 25 2022, 7:15 PM

looks good thanks

This revision is now accepted and ready to land.Jan 25 2022, 7:15 PM
This revision was landed with ongoing or failed builds.Jan 26 2022, 6:40 AM
This revision was automatically updated to reflect the committed changes.

Thanks for the reviews @omjavaid !