Fix GDB build when using --disable-gdbmi
Commit Message
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(-)
Comments
>>>>> "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
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
>>>>> "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
@@ -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);
@@ -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
@@ -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
@@ -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