This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Add RegisterFlags class
ClosedPublic

Authored by DavidSpickett on Mar 8 2023, 3:09 AM.

Details

Summary

This models the "flags" node from GDB's target XML:
https://sourceware.org/gdb/onlinedocs/gdb/Target-Description-Format.html

This node is used to describe the fields of registers like cpsr on AArch64.

RegisterFlags is a class that contains a list of register fields.
These fields will be extracted from the XML sent by the remote.

We assume that there is at least one field, that the fields are
sorted in descending order and do not overlap. That will be
enforced by the XML processor (the GDB client code in our case).

The fields may not cover the whole register. To account for this
RegisterFields will add anonymous padding fields so that
sizeof(all fields) == sizeof(register). This will save a lot
of hasssle later.

Diff Detail

Event Timeline

DavidSpickett created this revision.Mar 8 2023, 3:09 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 8 2023, 3:09 AM
DavidSpickett requested review of this revision.Mar 8 2023, 3:09 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 8 2023, 3:09 AM
tschuett added inline comments.
lldb/include/lldb/Target/RegisterFlags.h
21

There are a lot of const std::string& . Are you allowed to use llvm::StringRef or even std::string_view in LLDB?

lldb/unittests/Target/RegisterFlagsTest.cpp
124

Missing line.

DavidSpickett added inline comments.Mar 8 2023, 6:31 AM
lldb/include/lldb/Target/RegisterFlags.h
21

We can use llvm::StringRef, but in this case this will be passed a std::string so I just defaulted to the most conservative version (this happens in a later patch).

I suppose you could move here, or pass by copy and assume the compiler will figure it out.

DavidSpickett added inline comments.Mar 8 2023, 6:32 AM
lldb/include/lldb/Target/RegisterFlags.h
21

Actually, it doesn't have to be a std::string the XML parser does give you a StringRef.

I will update this and the subsequent patches.

My only comment is: views look more modern than const-ref. The efficiency is not affected at all.

Use StringRef for parameters. This is what the XML parser gives you
by default in any case.

Internally we want to keep a copy of the string because the XML document
will go away after parsing.

DavidSpickett marked an inline comment as done.

Add newline at end of file.

DavidSpickett marked an inline comment as done.Mar 8 2023, 7:56 AM
jasonmolenda accepted this revision.Mar 9 2023, 1:55 PM

LGTM. I'm not really advocating to changing m_type to be an enum, but curious how that might fit into the total context of this feature, and if it makes any sense.

lldb/include/lldb/Target/RegisterFlags.h
71

Should we store the type as an eFormat enum instead of a string? Maybe it's just informational for logging/humans and not too important. ProcessGDBRemote::BuildDynamicRegisterInfo translates our own register type names into these values (more often seen in the old lldb-created qRegisterInfos).

lldb/source/Target/RegisterFlags.cpp
50

describing

This revision is now accepted and ready to land.Mar 9 2023, 1:55 PM

Fix typo, remove m_type which is not used by the following patches.

We could use it down the road, but we can also just guess that single
bit fields are bools and anything else is a number. So we don't lose much.

Everything I've seen out of gdbserver only sends a type for the other
information types, struct and unions.

DavidSpickett marked 2 inline comments as done.Mar 10 2023, 5:23 AM
JDevlieghere accepted this revision.Mar 20 2023, 1:58 PM

LGTM modulo comments

lldb/include/lldb/Target/RegisterFlags.h
22–23

If you're going to store the string anyway, you might as well take it by value and move it into the member. That'll save you a copy in case someone calls the ctor with an rvalue reference.

27

This applies to the rest of this file as well.

73

Same here

82–84

Looks like these can be const?

Address review comments.

DavidSpickett marked 4 inline comments as done.Mar 21 2023, 2:27 AM

Use LOG instead of LOGF.

This revision was automatically updated to reflect the committed changes.