From 558d76c626a8cc5b393ecbe5f3cde5d8d26a9953 Mon Sep 17 00:00:00 2001 From: Luis Machado Date: Thu, 5 Nov 2020 13:10:08 -0300 Subject: [PATCH] Print shorter version of decoded capabilities In order to produce output that is not so verbose, we print the short version of the decoded capabilities instead. gdb/ChangeLog: 2020-11-11 Luis Machado * valprint.c (generic_value_print_capability): Use compact form. gdbsupport/ChangeLog: 2020-11-11 Luis Machado * capability.cc (cap_short_perms_strings): New static global. (capability::to_str): New argument COMPACT. Print contents based on the new argument. (capability::print): Update calls. * capability.h (capability::to_str): Update prototype and documentation. --- gdb/valprint.c | 2 +- gdbsupport/capability.cc | 40 ++++++++++++++++++++++++++++++++++++---- gdbsupport/capability.h | 7 +++++-- 3 files changed, 42 insertions(+), 7 deletions(-) diff --git a/gdb/valprint.c b/gdb/valprint.c index 2be4e5e4b44..5ee5a71af35 100644 --- a/gdb/valprint.c +++ b/gdb/valprint.c @@ -528,7 +528,7 @@ generic_value_print_capability (struct value *val, struct ui_file *stream, uint128_t dummy_cap; memcpy (&dummy_cap, contents, length); capability cap (dummy_cap, tag); - fprintf_filtered (stream, "%s", cap.to_str ().c_str ()); + fprintf_filtered (stream, "%s", cap.to_str (true).c_str ()); } return; diff --git a/gdbsupport/capability.cc b/gdbsupport/capability.cc index 1b01590d5ca..6551bab6784 100644 --- a/gdbsupport/capability.cc +++ b/gdbsupport/capability.cc @@ -76,6 +76,31 @@ static const char *cap_perms_strings[] = "Load" }; +/* Short version of permission string names, indexed by bit number from + permissions + Valid bits are 0 through 17. */ +static const char *cap_short_perms_strings[] = +{ + "G", + "E", + "U0", + "U1", + "U2", + "U3", + "MLd", + "CID", + "BrUn", + "Sys", + "Un", + "Sl", + "StLoC", + "StC", + "LdC", + "X", + "St", + "Ld" +}; + /* Returns a capability, derived from the input capability, with base address set to the value of the input capability and the length set to a given value. If precise bounds setting is not possible, either the bounds are @@ -523,10 +548,13 @@ capability::set_offset (uint64_t offset) set_value (get_base () + offset); } -/* Returns a string representation of the capability. */ +/* Returns a string representation of the capability. + + If COMPACT is true, use a less verbose form. Otherwise print + the more verbose version. */ std::string -capability::to_str (void) +capability::to_str (bool compact) { /* The printing format is the following: {tag = %d, address = 0x%016x, permissions = {[%s], otype = 0x%04x, @@ -549,7 +577,11 @@ capability::to_str (void) if (check_permissions (1 << i)) { perm_str += " "; - perm_str += cap_perms_strings [i]; + + if (compact) + perm_str += cap_short_perms_strings[i]; + else + perm_str += cap_perms_strings[i]; } perm_str += " ]"; @@ -581,7 +613,7 @@ capability::to_str (void) void capability::print (void) { - printf ("%s", to_str ().c_str ()); + printf ("%s", to_str (true).c_str ()); } /* UNIT TESTS - Exercise all the methods and primitives. Some of the tests diff --git a/gdbsupport/capability.h b/gdbsupport/capability.h index 817316ed0e3..fd94768e432 100644 --- a/gdbsupport/capability.h +++ b/gdbsupport/capability.h @@ -544,9 +544,12 @@ public: /* Printing functions. */ - /* Returns a string representation of the capability. */ + /* Returns a string representation of the capability. - std::string to_str (void); + If COMPACT is true, use a less verbose form. Otherwise print + the more verbose version. */ + + std::string to_str (bool compact); /* Print the capability. */ -- 2.47.2