binutils-gdb/gdbsupport
Pedro Alves 8c4f70ffe7 enum_flags to_string
This commit introduces shared infrastructure that can be used to
implement enum_flags -> to_string functions.  With this, if we want to
support converting a given enum_flags specialization to string, we
just need to implement a function that provides the enumerator->string
mapping, like so:

 enum some_flag
   {
     SOME_FLAG1 = 1 << 0,
     SOME_FLAG2 = 1 << 1,
     SOME_FLAG3 = 1 << 2,
   };

 DEF_ENUM_FLAGS_TYPE (some_flag, some_flags);

 static std::string
 to_string (some_flags flags)
 {
   static constexpr some_flags::string_mapping mapping[] = {
     MAP_ENUM_FLAG (SOME_FLAG1),
     MAP_ENUM_FLAG (SOME_FLAG2),
     MAP_ENUM_FLAG (SOME_FLAG3),
   };
   return flags.to_string (mapping);
 }

.. and then to_string(SOME_FLAG2 | SOME_FLAG3) produces a string like
"0x6 [SOME_FLAG2 SOME_FLAG3]".

If we happen to forget to update the mapping array when we introduce a
new enumerator, then the string representation will pretty-print the
flags it knows about, and then the leftover flags in hex (one single
number).  For example, if we had missed mapping SOME_FLAG2 above, we'd
end up with:

  to_string(SOME_FLAG2 | SOME_FLAG3)  => "0x6 [SOME_FLAG2 0x4]");

Other than in the unit tests included, no actual usage of the
functionality is added in this commit.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
Change-Id: I835de43c33d13bc0c95132f42c3f97318b875779
2023-01-30 15:03:55 -05:00
..
.dir-locals.el Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
.gitattributes
acinclude.m4 gdb: don't use -Wmissing-prototypes with g++ 2022-01-13 10:25:45 +00:00
aclocal.m4 gdb: use AC_PROG_CC_STDC instead of AM_PROG_CC_STDC 2020-10-31 08:30:57 -04:00
agent.cc Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
agent.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
alt-stack.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
array-view.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
ax.def Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
block-signals.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
break-common.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
btrace-common.cc Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
btrace-common.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
buffer.cc Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
buffer.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
buildargv.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
byte-vector.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
ChangeLog-2020-2021 gdb: move remaining ChangeLogs to legacy files 2021-07-26 12:20:33 +01:00
check-defines.el Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
cleanups.cc Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
cleanups.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
common-debug.cc Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
common-debug.h gdbsupport: fix scoped_debug_start_end's move constructor 2023-01-05 15:18:11 -05:00
common-defs.h Set _WIN32_WINNT in common.m4 configure check 2023-01-11 11:00:42 -07:00
common-exceptions.cc Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
common-exceptions.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
common-gdbthread.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
common-inferior.cc Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
common-inferior.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
common-regcache.cc Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
common-regcache.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
common-types.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
common-utils.cc Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
common-utils.h gdbsupport: add gdb::string_view_hash 2023-01-05 14:38:51 -05:00
common.m4 Set _WIN32_WINNT in common.m4 configure check 2023-01-11 11:00:42 -07:00
compiler-type.m4 Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
config.in gdbsupport: move libxxhash configure check to gdbsupport 2023-01-05 14:38:51 -05:00
configure Set _WIN32_WINNT in common.m4 configure check 2023-01-11 11:00:42 -07:00
configure.ac Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
create-version.sh Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
def-vector.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
default-init-alloc.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
eintr.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
enum-flags.h enum_flags to_string 2023-01-30 15:03:55 -05:00
environ.cc Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
environ.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
errors.cc Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
errors.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
event-loop.cc Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
event-loop.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
event-pipe.cc Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
event-pipe.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
fileio.cc Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
fileio.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
filestuff.cc Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
filestuff.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
filtered-iterator.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
format.cc Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
format.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
forward-scope-exit.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
function-view.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
gdb_assert.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
gdb_binary_search.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
gdb_file.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
gdb_locale.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
gdb_obstack.cc Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
gdb_obstack.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
gdb_optional.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
gdb_proc_service.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
gdb_ref_ptr.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
gdb_regex.cc Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
gdb_regex.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
gdb_select.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
gdb_setjmp.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
gdb_signals.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
gdb_splay_tree.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
gdb_string_view.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
gdb_string_view.tcc Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
gdb_sys_time.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
gdb_tilde_expand.cc Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
gdb_tilde_expand.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
gdb_unique_ptr.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
gdb_unlinker.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
gdb_vecs.cc Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
gdb_vecs.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
gdb_wait.cc Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
gdb_wait.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
gdb-checked-static-cast.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
gdb-dlfcn.cc Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
gdb-dlfcn.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
gdb-hashtab.cc Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
gdb-hashtab.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
gdb-safe-ctype.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
gdb-sigmask.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
gdb-xfree.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
hash_enum.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
host-defs.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
intrusive_list.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
invoke-result.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
iterator-range.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
job-control.cc Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
job-control.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
Makefile.am Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
Makefile.in gdbsupport: move libxxhash configure check to gdbsupport 2023-01-05 14:38:51 -05:00
netstuff.cc Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
netstuff.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
new-op.cc Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
next-iterator.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
observable.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
offset-type.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
packed.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
parallel-for.h Avoid submitting empty tasks in parallel_for_each 2023-01-17 07:03:26 -07:00
pathstuff.cc Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
pathstuff.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
poison.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
preprocessor.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
print-utils.cc Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
print-utils.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
ptid.cc Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
ptid.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
ptrace.m4 Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
range-chain.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
README
refcounted-object.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
reference-to-pointer-iterator.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
rsp-low.cc Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
rsp-low.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
run-time-clock.cc Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
run-time-clock.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
safe-iterator.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
safe-strerror.cc Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
scope-exit.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
scoped_fd.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
scoped_ignore_signal.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
scoped_ignore_sigttou.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
scoped_mmap.cc Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
scoped_mmap.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
scoped_restore.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
search.cc Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
search.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
selftest.cc Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
selftest.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
selftest.m4 Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
signals-state-save-restore.cc Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
signals-state-save-restore.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
signals.cc Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
symbol.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
tdesc.cc Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
tdesc.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
thread-pool.cc Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
thread-pool.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
traits.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
underlying.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
valid-expr.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
version.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
warning.m4 Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
x86-xstate.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
xml-utils.cc Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
xml-utils.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00

This is a helper library that is used by gdb and gdbserver.

To send patches, follow the gdb patch submission instructions in
../gdb/CONTRIBUTE.  For maintainers, see ../gdb/MAINTAINERS.