]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Add capability::metadata_str.
authorJohn Baldwin <jhb@FreeBSD.org>
Fri, 29 Jul 2022 01:03:03 +0000 (18:03 -0700)
committerJohn Baldwin <jhb@FreeBSD.org>
Thu, 1 Sep 2022 23:47:42 +0000 (16:47 -0700)
This returns a string of just the metadata for a capability.

capability::to_str uses this method when outputting the compact form.

gdbsupport/capability.cc
gdbsupport/capability.h

index e75b8f6de7b2e03f79fe17a6dde55e599e501667..a3993b4b90f687aac6e6898bdc299c28dee94357 100644 (file)
@@ -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 += "[";
index 9d518ac6dd09656779ffa6d02685da95aa6870e0..eb82f9dfbe47f96c4bf1de9f6324b1570c5d7055 100644 (file)
@@ -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