[PATCH] target debug: Improve printing of flags

Simon Marchi simon.marchi@ericsson.com
Thu Mar 1 17:04:00 GMT 2018


Currently, the target debug code prints flags as decimal integers:

  <- record-btrace->to_call_history (0x240d420, 10, 7)
  <- record-btrace->to_insn_history (0x240d420, 10, 62)
                                          flags ----^

This patch improves that to print an OR expression of the flags:

  <- record-btrace->to_call_history (0x240e420, 10, RECORD_PRINT_SRC_LINE | RECORD_PRINT_INSN_RANGE | RECORD_PRINT_INDENT_CALLS)
  <- record-btrace->to_insn_history (0x240e420, 10, DISASSEMBLY_RAW_INSN | DISASSEMBLY_OMIT_FNAME | DISASSEMBLY_FILENAME | DISASSEMBLY_OMIT_PC | DISASSEMBLY_SOURCE)

Since the list of possible flags is hand-written in the debug functions,
it is possible that we forget to add one there when we add a new flag.
In that case, it will be printed in hex (RECORD_PRINT_SRC_LINE | 0x8),
so we forgot to consider a possible flag here.

gdb/ChangeLog:

	* target-debug.h (target_debug_print_gdb_disassembly_flags):
	Change to a function, print flags.
	(target_debug_print_record_print_flags): Likewise.
	(target_debug_print_flag): New macro.
	(target_debug_print_remaining_flags): New function.
---
 gdb/target-debug.h | 45 +++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 41 insertions(+), 4 deletions(-)

diff --git a/gdb/target-debug.h b/gdb/target-debug.h
index 71d1a3f..19a5ab9 100644
--- a/gdb/target-debug.h
+++ b/gdb/target-debug.h
@@ -164,16 +164,53 @@
   target_debug_do_print (host_address_to_string (X))
 #define target_debug_print_enum_remove_bp_reason(X) \
   target_debug_do_print (plongest (X))
-#define target_debug_print_gdb_disassembly_flags(X) \
-  target_debug_do_print (plongest (X))
 #define target_debug_print_traceframe_info_up(X) \
   target_debug_do_print (host_address_to_string (X.get ()))
 #define target_debug_print_gdb_array_view_const_int(X)	\
   target_debug_do_print (host_address_to_string (X.data ()))
 #define target_debug_print_inferior_p(inf) \
   target_debug_do_print (host_address_to_string (inf))
-#define target_debug_print_record_print_flags(X) \
-  target_debug_do_print (plongest (X))
+
+#define target_debug_print_flag(flags, enumerator, first) \
+  if (flags & enumerator) \
+    { \
+      flags &= ~enumerator; \
+      gdb_stdlog->printf ("%s" STRINGIFY (enumerator) "", first ? "" : " | "); \
+      first = false; \
+    }
+
+static void
+target_debug_print_remaining_flags (int flags, bool first)
+{
+  if (flags != 0 || first)
+    gdb_stdlog->printf ("%s0x%x", first ? "" : " | ", (int) flags);
+}
+
+static void
+target_debug_print_record_print_flags (record_print_flags flags)
+{
+  bool first = true;
+
+  target_debug_print_flag (flags, RECORD_PRINT_SRC_LINE, first);
+  target_debug_print_flag (flags, RECORD_PRINT_INSN_RANGE, first);
+  target_debug_print_flag (flags, RECORD_PRINT_INDENT_CALLS, first);
+  target_debug_print_remaining_flags (flags, first);
+}
+
+static void
+target_debug_print_gdb_disassembly_flags (gdb_disassembly_flags flags)
+{
+  bool first = true;
+
+  target_debug_print_flag (flags, DISASSEMBLY_SOURCE_DEPRECATED, first);
+  target_debug_print_flag (flags, DISASSEMBLY_RAW_INSN, first);
+  target_debug_print_flag (flags, DISASSEMBLY_OMIT_FNAME, first);
+  target_debug_print_flag (flags, DISASSEMBLY_FILENAME, first);
+  target_debug_print_flag (flags, DISASSEMBLY_OMIT_PC, first);
+  target_debug_print_flag (flags, DISASSEMBLY_SOURCE, first);
+  target_debug_print_flag (flags, DISASSEMBLY_SPECULATIVE, first);
+  target_debug_print_remaining_flags (flags, first);
+}
 
 static void
 target_debug_print_struct_target_waitstatus_p (struct target_waitstatus *status)
-- 
2.7.4



More information about the Gdb-patches mailing list