From: John Baldwin Date: Fri, 29 Jul 2022 01:03:03 +0000 (-0700) Subject: Add capability::metadata_str. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cbec413578b37cb862ae9fa81c6fa4a5b9e2ee71;p=thirdparty%2Fbinutils-gdb.git Add capability::metadata_str. This returns a string of just the metadata for a capability. capability::to_str uses this method when outputting the compact form. --- diff --git a/gdbsupport/capability.cc b/gdbsupport/capability.cc index e75b8f6de7b..a3993b4b90f 100644 --- a/gdbsupport/capability.cc +++ b/gdbsupport/capability.cc @@ -531,6 +531,61 @@ bool capability::is_null_derived (void) return _bits (m_cap, 127, 64) == 0; } +/* Returns a string representation of capability metadata. */ + +std::string +capability::metadata_str (void) +{ + if (is_null_derived ()) + return {}; + + std::string cap_str (" ["); + + /* Handle compact permissions output. */ + if (check_permissions (1 << cap_perms_load)) + cap_str += "r"; + if (check_permissions (1 << cap_perms_store)) + cap_str += "w"; + if (check_permissions (1 << cap_perms_execute)) + cap_str += "x"; + if (check_permissions (1 << cap_perms_load_cap)) + cap_str += "R"; + if (check_permissions (1 << cap_perms_store_cap)) + cap_str += "W"; + if (check_permissions (1 << cap_perms_executive)) + cap_str += "E"; + + /* Handle capability range. */ + cap_str += ","; + cap_str += core_addr_to_string_nz (get_base ()); + cap_str += "-"; + cap_str += core_addr_to_string_nz (get_limit ()); + cap_str += "]"; + + std::string attr_str (""); + + /* Handle attributes. */ + if (get_tag () == false) + attr_str += "invalid"; + if (get_otype () == CAP_SEAL_TYPE_RB) + { + if (!attr_str.empty ()) + attr_str += ","; + attr_str += "sentry"; + } + if (is_sealed ()) + { + if (!attr_str.empty ()) + attr_str += ","; + attr_str += "sealed"; + } + + if (!attr_str.empty ()) + cap_str += " (" + attr_str + ")"; + + return cap_str; +} + /* Returns a string representation of the capability. If COMPACT is true, use a less verbose form. Otherwise print @@ -565,61 +620,14 @@ capability::to_str (bool compact) if (is_null_derived ()) return val_str; - std::string cap_str (""); - std::string perm_str (""); - std::string range_str (""); - /* Format 2. */ if (compact) - { - /* Handle compact permissions output. */ - if (check_permissions (1 << cap_perms_load)) - perm_str += "r"; - if (check_permissions (1 << cap_perms_store)) - perm_str += "w"; - if (check_permissions (1 << cap_perms_execute)) - perm_str += "x"; - if (check_permissions (1 << cap_perms_load_cap)) - perm_str += "R"; - if (check_permissions (1 << cap_perms_store_cap)) - perm_str += "W"; - if (check_permissions (1 << cap_perms_executive)) - perm_str += "E"; - - /* Handle capability range. */ - range_str += core_addr_to_string_nz (get_base ()); - range_str += "-"; - range_str += core_addr_to_string_nz (get_limit ()); - - std::string attr1_str (""); - std::string attr2_str (""); - std::string attr3_str (""); - - /* Handle attributes. */ - if (get_tag () == false) - attr1_str = "invalid"; - if (get_otype () == CAP_SEAL_TYPE_RB) - { - if (!attr1_str.empty ()) - attr2_str += ","; - attr2_str += "sentry"; - } - if (is_sealed ()) - { - if (!attr1_str.empty () || !attr2_str.empty ()) - attr3_str += ","; - attr3_str += "sealed"; - } - - cap_str += val_str + " [" + perm_str + "," + range_str + "]"; - - if (!attr1_str.empty () || !attr2_str.empty () || !attr3_str.empty ()) - cap_str += " (" + attr1_str + attr2_str + attr3_str + ")"; - - return cap_str; - } + return val_str + metadata_str (); /* Format 3. */ + std::string cap_str (""); + std::string perm_str (""); + std::string range_str (""); /* Permissions. */ perm_str += "["; diff --git a/gdbsupport/capability.h b/gdbsupport/capability.h index 9d518ac6dd0..eb82f9dfbe4 100644 --- a/gdbsupport/capability.h +++ b/gdbsupport/capability.h @@ -552,6 +552,10 @@ public: /* Printing functions. */ + /* Returns a string representation of capability metadata. */ + + std::string metadata_str (void); + /* Returns a string representation of the capability. If COMPACT is true, use a less verbose form. Otherwise print