Patchwork Fix GDB build when using --disable-gdbmi

login
register
mail settings
Submitter Simon Marchi
Date May 10, 2019, 6:35 p.m.
Message ID <20190510183512.9955-1-simon.marchi@efficios.com>
Download mbox | patch
Permalink /patch/32638/
State New
Headers show

Comments

Simon Marchi - May 10, 2019, 6:35 p.m.
Since commit

    b4be1b064860 ("Fix MI output for multi-location breakpoints")

we get this error when building with --disable-gdbmi:

      CXXLD  gdb
    /home/smarchi/src/binutils-gdb/gdb/breakpoint.c:6358: error: undefined reference to 'mi_multi_location_breakpoint_output_fixed(ui_out*)'

This is due to breakpoint.c using a function defined in mi/mi-main.c, even
though mi/mi-main.c isn't included in the build.

To fix it, I added a config.h macro, HAVE_GDBMI, defined if we build
with GDB/MI support.  We can then use it in breakpoint.c to
conditionally use mi_multi_location_breakpoint_output_fixed.  If
building without GDB/MI, the value of use_fixed_output is not really
important, as it is only used to fix an issue when printing breakpoints
in MI.

gdb/ChangeLog:

	* configure.ac: Define HAVE_GDBMI if building with GDB/MI
	support.
	* configure, config.in: Re-generate.
	* breakpoint.c (print_one_breakpoint): Use
	mi_multi_location_breakpoint_output_fixed only if HAVE_GDBMI is
	defined.
---
 gdb/breakpoint.c | 7 ++++++-
 gdb/config.in    | 3 +++
 gdb/configure    | 3 +++
 gdb/configure.ac | 1 +
 4 files changed, 13 insertions(+), 1 deletion(-)
Tom Tromey - May 10, 2019, 6:47 p.m.
>>>>> "Simon" == Simon Marchi <simon.marchi@efficios.com> writes:

Simon> To fix it, I added a config.h macro, HAVE_GDBMI, defined if we build
Simon> with GDB/MI support.  We can then use it in breakpoint.c to
Simon> conditionally use mi_multi_location_breakpoint_output_fixed.  If
Simon> building without GDB/MI, the value of use_fixed_output is not really
Simon> important, as it is only used to fix an issue when printing breakpoints
Simon> in MI.

I'm not sure if it's better or not, but ui_out has a "flags" feature
that could be applied to this.  This would mean not having to have a #if.

Tom
Simon Marchi - May 10, 2019, 6:57 p.m.
On 2019-05-10 2:47 p.m., Tom Tromey wrote:
>>>>>> "Simon" == Simon Marchi <simon.marchi@efficios.com> writes:
> 
> Simon> To fix it, I added a config.h macro, HAVE_GDBMI, defined if we build
> Simon> with GDB/MI support.  We can then use it in breakpoint.c to
> Simon> conditionally use mi_multi_location_breakpoint_output_fixed.  If
> Simon> building without GDB/MI, the value of use_fixed_output is not really
> Simon> important, as it is only used to fix an issue when printing breakpoints
> Simon> in MI.
> 
> I'm not sure if it's better or not, but ui_out has a "flags" feature
> that could be applied to this.  This would mean not having to have a #if.

I don't think this will work (or I don't understand what you suggest).

If we do

  bool use_fixed_output = ui_out->test_flags(ui_out_flag::fixed_breakpoint_output);

That would require the mi_ui_out object to be created with that flag.  However,
this option can be toggled on after the mi_ui_out object has been created (through
the MI command -fix-multi-location-breakpoint-output).

One way to make it work would be, when the -fix-multi-location-breakpoint-output
command is issued, we go through all existing ui_out objects and set that flag.
But I don't think there's an easy way of going through all existing ui_out objects.

If you have any ideas for a more elegant way to make it work, I would be up for it,
because it's true that sprinkling #ifdefs is not the best idea.

Simon
Tom Tromey - May 10, 2019, 7:11 p.m.
>>>>> "Simon" == Simon Marchi <simon.marchi@efficios.com> writes:

Simon> That would require the mi_ui_out object to be created with that flag.  However,
Simon> this option can be toggled on after the mi_ui_out object has been created (through
Simon> the MI command -fix-multi-location-breakpoint-output).

Ah, I didn't realize that.

Simon> One way to make it work would be, when the -fix-multi-location-breakpoint-output
Simon> command is issued, we go through all existing ui_out objects and set that flag.
Simon> But I don't think there's an easy way of going through all existing ui_out objects.

Simon> If you have any ideas for a more elegant way to make it work, I would be up for it,
Simon> because it's true that sprinkling #ifdefs is not the best idea.

It's maybe strange that -fix-multi-location-breakpoint-output affects
all MI channels and not just the ones associated with the request.  It
seems like if there are multiple MI channels, then this could confuse
some client.  But then, making it per-channel would make it not work
nicely if a new MI-out is created for a specific command (which I guess
is done by mi_load_progress, not sure about things like interpreter-exec).

I guess maybe if there's going to be a global, it could just be stuck in
breakpoint.c and then flags used for the ui-out version check currently
done in mi_multi_location_breakpoint_output_fixed.  I'm not really sure
this is any better -- globals are bad, but it does avoid the #if.

Tom

Patch

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index f6d2f36d0a40..8f75c7658080 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -6355,7 +6355,12 @@  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);
+  bool use_fixed_output
+#ifdef HAVE_GDBMI
+    = mi_multi_location_breakpoint_output_fixed (uiout);
+#else
+    = true;
+#endif
 
   gdb::optional<ui_out_emit_tuple> bkpt_tuple_emitter (gdb::in_place, uiout, "bkpt");
   print_one_breakpoint_location (b, NULL, 0, last_loc, allflag);
diff --git a/gdb/config.in b/gdb/config.in
index c0291fbd9c53..e5a19bda6bd6 100644
--- a/gdb/config.in
+++ b/gdb/config.in
@@ -174,6 +174,9 @@ 
 /* Define if <sys/procfs.h> has fpregset_t. */
 #undef HAVE_FPREGSET_T
 
+/* Define to 1 if building with GDB/MI support. */
+#undef HAVE_GDBMI
+
 /* Define to 1 if you have the `getauxval' function. */
 #undef HAVE_GETAUXVAL
 
diff --git a/gdb/configure b/gdb/configure
index 15a96afcca8a..ca797473bfc1 100755
--- a/gdb/configure
+++ b/gdb/configure
@@ -6825,6 +6825,9 @@  if test x"$enable_gdbmi" = xyes; then
     CONFIG_DEPS="$CONFIG_DEPS \$(SUBDIR_MI_DEPS)"
     CONFIG_SRCS="$CONFIG_SRCS \$(SUBDIR_MI_SRCS)"
     ENABLE_CFLAGS="$ENABLE_CFLAGS \$(SUBDIR_MI_CFLAGS)"
+
+$as_echo "#define HAVE_GDBMI 1" >>confdefs.h
+
   fi
 fi
 
diff --git a/gdb/configure.ac b/gdb/configure.ac
index 1318c8d00873..66f72c5158d4 100644
--- a/gdb/configure.ac
+++ b/gdb/configure.ac
@@ -315,6 +315,7 @@  if test x"$enable_gdbmi" = xyes; then
     CONFIG_DEPS="$CONFIG_DEPS \$(SUBDIR_MI_DEPS)"
     CONFIG_SRCS="$CONFIG_SRCS \$(SUBDIR_MI_SRCS)"
     ENABLE_CFLAGS="$ENABLE_CFLAGS \$(SUBDIR_MI_CFLAGS)"
+    AC_DEFINE([HAVE_GDBMI], 1, [Define to 1 if building with GDB/MI support.])
   fi
 fi