public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [commit+doco] Trust PAD types instead of using PAD___XVS.
@ 2010-01-18  9:51 Joel Brobecker
  2010-01-18 17:59 ` Eli Zaretskii
  0 siblings, 1 reply; 4+ messages in thread
From: Joel Brobecker @ 2010-01-18  9:51 UTC (permalink / raw)
  To: gdb-patches

From: brobecke <brobecke@f8352e7e-cb20-0410-8ce7-b5d9e71c585c>

This change removes a work-around that was introduced due to a bug
in the debug info generated by the compiler.  Eric fixed the problem
for us, and thus the workaround is no longer necessary.  Removing
the workaround allows us to avoid a parallel-type lookup, so this
change is intersting on two levels.

The problem is that this change makes the assumption that the debugging
info is correct, which is only true for recent compilers.  To help with
potential compatibility issues, this patch introduces a new setting
that allows the user to restore the older (less efficient) approach:
set/show ada trust-PAD-over-XVS.

Since there are new settings, NEWS and doco updates are attached.

gdb/ChangeLog:

        * ada-lang.c (trust_pad_over_xvs): New static variable.
        (ada_is_aligner_type): If !trust_pad_over_xvs and there is a
        parallel XVS type, follow the XVS type instead of the PAD type.
        (unwrap_value): Make sure that there is no parallel XVE type
        before returning the value as is.
        (set_ada_list, show_ada_list): New static variables.
        (set_ada_command, show_ada_command): New functions.
        (_initialize_ada_language): Add new "set/show ada" prefix commands.
        Add new "set/show ada trust-PAD-over-XVS" setting.
        * NEWS: Add entry for "set/show ada trust-PAD-over-XVS" commands.

gdb/doc/ChangeLog:

        * gdb.texinfo (Ada Glitches): Document new settings
        "set/show ada trust-PAD-over-XVS".

OK to commit the NEWS & doco bits?

Thanks,
-- 
Joel

---
 gdb/NEWS            |    9 +++++++
 gdb/ada-lang.c      |   66 ++++++++++++++++++++++++++++++++++++++++++++++----
 gdb/doc/gdb.texinfo |   28 +++++++++++++++++++++
 3 files changed, 97 insertions(+), 6 deletions(-)

diff --git a/gdb/NEWS b/gdb/NEWS
index 4b88ee7..7d97a2f 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -163,6 +163,15 @@ show disconnected-tracing
    loses its connection to GDB.  If 0, the target is to stop tracing
    upon disconnection.
 
+set ada trust-PAD-over-XVS on|off
+show ada trust-PAD-over-XVS
+   If off, activate a workaround against a bug in the debugging information
+   generated by the compiler for PAD types (see gcc/exp_dbug.ads in
+   the GCC sources for more information about the GNAT encoding and
+   PAD types in particular).  It is always safe to set this option to
+   off, but this introduces a slight performance penalty.  The default
+   is on.
+
 * New remote packets
 
 QTDV
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 2f16644..e63cf88 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -7727,6 +7727,16 @@ ada_is_string_type (struct type *type)
     return 0;
 }
 
+/* The compiler sometimes provides a parallel XVS type for a given
+   PAD type.  Normally, it is safe to follow the PAD type directly,
+   but older versions of the compiler have a bug that causes the offset
+   of its "F" field to be wrong.  Following that field in that case
+   would lead to incorrect results, but this can be worked around
+   by ignoring the PAD type and using the associated XVS type instead.
+
+   Set to True if the debugger should trust the contents of PAD types.
+   Otherwise, ignore the PAD type if there is a parallel XVS type.  */
+static int trust_pad_over_xvs = 1;
 
 /* True if TYPE is a struct type introduced by the compiler to force the
    alignment of a value.  Such types have a single field with a
@@ -7737,10 +7747,7 @@ ada_is_aligner_type (struct type *type)
 {
   type = ada_check_typedef (type);
 
-  /* If we can find a parallel XVS type, then the XVS type should
-     be used instead of this type.  And hence, this is not an aligner
-     type.  */
-  if (ada_find_parallel_type (type, "___XVS") != NULL)
+  if (!trust_pad_over_xvs && ada_find_parallel_type (type, "___XVS") != NULL)
     return 0;
 
   return (TYPE_CODE (type) == TYPE_CODE_STRUCT
@@ -7918,8 +7925,11 @@ unwrap_value (struct value *val)
       struct type *raw_real_type =
         ada_check_typedef (ada_get_base_type (type));
 
-      if (type == raw_real_type)
-        return val;
+      /* If there is no parallel XVS or XVE type, then the value is
+	 already unwrapped.  Return it without further modification.  */
+      if ((type == raw_real_type)
+	  && ada_find_parallel_type (type, "___XVE") == NULL)
+	return val;
 
       return
         coerce_unspec_val_to_type
@@ -11373,11 +11383,55 @@ const struct language_defn ada_language_defn = {
 /* Provide a prototype to silence -Wmissing-prototypes.  */
 extern initialize_file_ftype _initialize_ada_language;
 
+/* Command-list for the "set/show ada" prefix command.  */
+static struct cmd_list_element *set_ada_list;
+static struct cmd_list_element *show_ada_list;
+
+/* Implement the "set ada" prefix command.  */
+
+static void
+set_ada_command (char *arg, int from_tty)
+{
+  printf_unfiltered (_(\
+"\"set ada\" must be followed by the name of a setting.\n"));
+  help_list (set_ada_list, "set ada ", -1, gdb_stdout);
+}
+
+/* Implement the "show ada" prefix command.  */
+
+static void
+show_ada_command (char *args, int from_tty)
+{
+  cmd_show_list (show_ada_list, from_tty, "");
+}
+
 void
 _initialize_ada_language (void)
 {
   add_language (&ada_language_defn);
 
+  add_prefix_cmd ("ada", no_class, set_ada_command,
+                  _("Prefix command for changing Ada-specfic settings"),
+                  &set_ada_list, "set ada ", 0, &setlist);
+
+  add_prefix_cmd ("ada", no_class, show_ada_command,
+                  _("Generic command for showing Ada-specific settings."),
+                  &show_ada_list, "show ada ", 0, &showlist);
+
+  add_setshow_boolean_cmd ("trust-PAD-over-XVS", class_obscure,
+                           &trust_pad_over_xvs, _("\
+Enable or disable an optimization trusting PAD types over XVS types"), _("\
+Show whether an optimization trusting PAD types over XVS types is activated"),
+                           _("\
+This is related to the encoding used by the GNAT compiler.  The debugger\n\
+should normally trust the contents of PAD types, but certain older versions\n\
+of GNAT have a bug that sometimes causes the information in the PAD type\n\
+to be incorrect.  Turning this setting \"off\" allows the debugger to\n\
+work around this bug.  It is always safe to turn this option \"off\", but\n\
+this incurs a slight performance penalty, so it is recommended to NOT change\n\
+this option to \"off\" unless necessary."),
+                            NULL, NULL, &set_ada_list, &show_ada_list);
+
   varsize_limit = 65536;
 
   obstack_init (&symbol_list_obstack);
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 7cf1bb4..d3edcf8 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -12846,6 +12846,34 @@ by qualifying the problematic names with package
 @code{Standard} explicitly.  
 @end itemize
 
+Older versions of the compiler sometimes generate erroneous debugging
+information, resulting in the debugger incorrectly printing the value
+of affected entities.  In some cases, the debugger is able to work
+around an issue automatically. In other cases, the debugger is able
+to work around the issue, but the work-around has to be specifically
+enabled.
+
+@kindex set ada trust-PAD-over-XVS
+@kindex show ada trust-PAD-over-XVS
+@table @code
+
+@item set ada trust-PAD-over-XVS on
+Configure GDB to strictly follow the GNAT encoding when computing the
+value of Ada entities, particularly when @code{PAD} and @code{PAD___XVS}
+types are involved (see @code{ada/exp_dbug.ads} in the GCC sources for
+a complete description of the encoding used by the GNAT compiler).
+This is the default.
+
+@item set ada trust-PAD-over-XVS off
+This is related to the encoding using by the GNAT compiler.  If @value{GDBN}
+sometimes prints the wrong value for certain entities, changing @code{ada
+trust-PAD-over-XVS} to @code{off} activates a work-around which may fix
+the issue.  It is always safe to set @code{ada trust-PAD-over-XVS} to
+@code{off}, but this incurs a slight performance penalty, so it is
+recommended to leave this setting to @code{on} unless necessary.
+
+@end table
+
 @node Unsupported Languages
 @section Unsupported Languages
 
-- 
1.6.3.3

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [commit+doco] Trust PAD types instead of using PAD___XVS.
  2010-01-18  9:51 [commit+doco] Trust PAD types instead of using PAD___XVS Joel Brobecker
@ 2010-01-18 17:59 ` Eli Zaretskii
  2010-01-19 10:42   ` Joel Brobecker
  0 siblings, 1 reply; 4+ messages in thread
From: Eli Zaretskii @ 2010-01-18 17:59 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: gdb-patches

> From: Joel Brobecker <brobecker@adacore.com>
> Date: Mon, 18 Jan 2010 13:51:11 +0400
> 
> gdb/doc/ChangeLog:
> 
>         * gdb.texinfo (Ada Glitches): Document new settings
>         "set/show ada trust-PAD-over-XVS".
> 
> OK to commit the NEWS & doco bits?

Yes, but I have a question: if this is an obscure setting needed in
some marginal cases, shouldn't it be a "maint" command?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [commit+doco] Trust PAD types instead of using PAD___XVS.
  2010-01-18 17:59 ` Eli Zaretskii
@ 2010-01-19 10:42   ` Joel Brobecker
  2010-01-19 16:40     ` Tom Tromey
  0 siblings, 1 reply; 4+ messages in thread
From: Joel Brobecker @ 2010-01-19 10:42 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: gdb-patches

> > gdb/doc/ChangeLog:
> > 
> >         * gdb.texinfo (Ada Glitches): Document new settings
> >         "set/show ada trust-PAD-over-XVS".
> > 
> > OK to commit the NEWS & doco bits?
> 
> Yes

Thanks. Now checked in.

> , but I have a question: if this is an obscure setting needed in
> some marginal cases, shouldn't it be a "maint" command?

I thought about it, and then decided against it: I think that "maint"
commands should provide commands that really apply only to the
maintainers, commands that allow us to dump data structures, diagnose
inconstencies, issues, etc... It's really a judgment call, as we
probably have not been completely consistent in the way we name our
commands...

-- 
Joel

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [commit+doco] Trust PAD types instead of using PAD___XVS.
  2010-01-19 10:42   ` Joel Brobecker
@ 2010-01-19 16:40     ` Tom Tromey
  0 siblings, 0 replies; 4+ messages in thread
From: Tom Tromey @ 2010-01-19 16:40 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: Eli Zaretskii, gdb-patches

>>>>> "Joel" == Joel Brobecker <brobecker@adacore.com> writes:

Joel> I thought about it, and then decided against it: I think that "maint"
Joel> commands should provide commands that really apply only to the
Joel> maintainers

I tend to agree.

Joel> It's really a judgment call, as we probably have not been
Joel> completely consistent in the way we name our commands...

True, but that doesn't mean we must avoid having a rule for the future :-)

Tom

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-01-19 16:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-01-18  9:51 [commit+doco] Trust PAD types instead of using PAD___XVS Joel Brobecker
2010-01-18 17:59 ` Eli Zaretskii
2010-01-19 10:42   ` Joel Brobecker
2010-01-19 16:40     ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).