Fix MI output for multi-location breakpoints
[deliverable/binutils-gdb.git] / gdb / breakpoint.c
index 9be99ff4efae2394bef1392c703fbd6e6e397ccf..dd122be35bf3ba3efb4e9ee4bb53733643d364f9 100644 (file)
@@ -69,6 +69,7 @@
 #include "thread-fsm.h"
 #include "tid-parse.h"
 #include "cli/cli-style.h"
+#include "mi/mi-main.h"
 
 /* readline include files */
 #include "readline/readline.h"
@@ -6361,12 +6362,15 @@ print_one_breakpoint (struct breakpoint *b,
                      int allflag)
 {
   struct ui_out *uiout = current_uiout;
+  bool use_fixed_output = mi_multi_location_breakpoint_output_fixed (uiout);
 
-  {
-    ui_out_emit_tuple tuple_emitter (uiout, "bkpt");
+  gdb::optional<ui_out_emit_tuple> bkpt_tuple_emitter (gdb::in_place, uiout, "bkpt");
+  print_one_breakpoint_location (b, NULL, 0, last_loc, allflag);
 
-    print_one_breakpoint_location (b, NULL, 0, last_loc, allflag);
-  }
+  /* The mi2 broken format: the main breakpoint tuple ends here, the locations
+     are outside.  */
+  if (!use_fixed_output)
+    bkpt_tuple_emitter.reset ();
 
   /* If this breakpoint has custom print function,
      it's already printed.  Otherwise, print individual
@@ -6384,12 +6388,18 @@ print_one_breakpoint (struct breakpoint *b,
          && !is_hardware_watchpoint (b)
          && (b->loc->next || !b->loc->enabled))
        {
-         struct bp_location *loc;
-         int n = 1;
+         gdb::optional<ui_out_emit_list> locations_list;
+
+         /* For MI version <= 2, keep the behavior where GDB outputs an invalid
+            MI record.  For later versions, place breakpoint locations in a
+            list.  */
+         if (uiout->is_mi_like_p () && use_fixed_output)
+           locations_list.emplace (uiout, "locations");
 
-         for (loc = b->loc; loc; loc = loc->next, ++n)
+         int n = 1;
+         for (bp_location *loc = b->loc; loc != NULL; loc = loc->next, ++n)
            {
-             ui_out_emit_tuple tuple_emitter (uiout, NULL);
+             ui_out_emit_tuple loc_tuple_emitter (uiout, NULL);
              print_one_breakpoint_location (b, loc, n, last_loc, allflag);
            }
        }
This page took 0.028825 seconds and 4 git commands to generate.