public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gdb: dwarf2read: implement handling of variables in Fortran common block
@ 2016-03-30  5:32 G Helffrich
  2016-04-11 22:01 ` Luis Machado
  0 siblings, 1 reply; 2+ messages in thread
From: G Helffrich @ 2016-03-30  5:32 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 8629 bytes --]

This patch allows the gdb DWARF reader to handle variables located in Fortran common blocks.  This fixes 20 unexpected failures in the gdb.fortran testsuite with host, target and build triplet x86_64-apple-darwin13.4.0 with gfortran 4.9.2.

gdb/ChangeLog:

2015-03-30  George Helffrich  <ghfbsd@gmail.com>

        * dwarf2read.c (read_common_block): Relocate symbols in Fortran common
          blocks properly.
          (read_new_symbol_full): Don't discard zero-offset symbols in Fortran
          common blocks.
          (_initialize_dwarf2_read): Add debug diagnostic print for common
          symbols.
        * psymtab.c (print_partial_symbols): Recognize and print
          COMMON_BLOCK_DOMAIN.
        * symmisc.c (print_symbol):  Recognize and dump LOC_COMMON_BLOCK.

---

--- dwarf2read.c.orig   2015-02-21 02:11:44.000000000 +0900
+++ dwarf2read.c        2016-03-29 19:43:48.000000000 +0900
@@ -84,6 +84,9 @@ static unsigned int dwarf2_read_debug = 
 /* When non-zero, dump DIEs after they are read in.  */
 static unsigned int dwarf2_die_debug = 0;
 
+/* When non-zero, report definition of common block variables.  */
+static unsigned int dwarf2_common_debug = 0;
+
 /* When non-zero, cross-check physname against demangler.  */
 static int check_physname = 0;
 
@@ -13877,6 +13880,57 @@ static void
 read_common_block (struct die_info *die, struct dwarf2_cu *cu)
 {
   struct attribute *attr;
+  CORE_ADDR baseaddr;
+  struct program_space *psp;
+  struct minimal_symbol *msym = NULL;
+  struct objfile *objfile = cu->objfile;
+  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+  const char *name;
+
+  attr = dwarf2_attr (die, DW_AT_name, cu);
+  name = dwarf2_compute_name (NULL, die, cu, 1);
+  if (dwarf2_common_debug)
+    {
+      fprintf_unfiltered (gdb_stdlog,
+                         "Read common blk %s (%s)\n",
+                         DW_STRING(attr), name);
+    }
+  ALL_PSPACES (psp)
+    ALL_PSPACE_OBJFILES (psp, objfile)
+      if (objfile->flags & OBJF_MAINLINE) goto found;
+found:
+  if (objfile->flags & OBJF_MAINLINE)
+    ALL_OBJFILE_MSYMBOLS (objfile, msym)
+      {
+        struct obj_section *section = MSYMBOL_OBJ_SECTION (objfile, msym);
+
+        if (0 == strcmp(MSYMBOL_LINKAGE_NAME (msym), name))
+          {
+            if (dwarf2_common_debug)
+             {
+               fprintf_unfiltered (gdb_stdlog, "  Found %s at ", name);
+               fputs_filtered (paddress (gdbarch,
+                                         MSYMBOL_VALUE_ADDRESS (objfile, msym)),
+                                gdb_stdlog);
+             }
+            if (section && dwarf2_common_debug)
+              {
+                if (section->the_bfd_section != NULL)
+                  fprintf_filtered (gdb_stdlog, " section %s",
+                                    bfd_section_name (objfile->obfd,
+                                                section->the_bfd_section));
+                else
+                 fprintf_filtered (gdb_stdlog, " spurious section %ld",
+                                    (long) (section - objfile->sections));
+             }
+            if (dwarf2_common_debug)
+             fprintf_unfiltered (gdb_stdlog, "\n");
+
+           /* Found base of common, now use it to relocate symbols in it */
+            baseaddr = MSYMBOL_VALUE_ADDRESS (objfile, msym);
+           break;
+         }
+      }
 
   attr = dwarf2_attr (die, DW_AT_location, cu);
   if (attr)
@@ -13958,6 +14012,31 @@ read_common_block (struct die_info *die,
                  else
                    dwarf2_complex_location_expr_complaint ();
                }
+
+             if (dwarf2_common_debug)
+               {
+                 struct attribute *name = dwarf2_attr (child_die, DW_AT_name, cu);
+                 fprintf_unfiltered (gdb_stdlog,
+                                    "  Define common blk var %s at ",
+                                    DW_STRING(name));
+                 fputs_filtered (paddress (gdbarch,
+                                           SYMBOL_VALUE_ADDRESS (sym)),
+                                 gdb_stdlog);
+                 fputs_filtered (" -> ", gdb_stdlog);
+                 if (msym)
+                   fputs_filtered (paddress (gdbarch,
+                                             SYMBOL_VALUE_ADDRESS (sym)
+                                             + baseaddr),
+                                    gdb_stdlog);
+                 else
+                   fputs_filtered ("(unknown)", gdb_stdlog);
+                 fputs_filtered ("\n", gdb_stdlog);
+               }
+
+             /* Relocate symbol in common block */
+             if (msym)
+               SYMBOL_VALUE_ADDRESS (sym) += baseaddr;
+
            }
        }
 
@@ -18165,6 +18244,8 @@ new_symbol_full (struct die_info *die, s
          attr = dwarf2_attr (die, DW_AT_location, cu);
          if (attr)
            {
+             unsigned int fortran_common_symbol = 0;
+
              var_decode_location (attr, sym, cu);
              attr2 = dwarf2_attr (die, DW_AT_external, cu);
 
@@ -18172,16 +18253,23 @@ new_symbol_full (struct die_info *die, s
                 scope by DW_TAG_common_block.  */
              if (cu->language == language_fortran && die->parent
                  && die->parent->tag == DW_TAG_common_block)
-               attr2 = NULL;
+               {
+                 attr2 = NULL;
+                 fortran_common_symbol = 1;
+               }
 
              if (SYMBOL_CLASS (sym) == LOC_STATIC
                  && SYMBOL_VALUE_ADDRESS (sym) == 0
+                 && !fortran_common_symbol
                  && !dwarf2_per_objfile->has_section_at_zero)
                {
                  /* When a static variable is eliminated by the linker,
                     the corresponding debug information is not stripped
                     out, but the variable address is set to null;
-                    do not add such variables into symbol table.  */
+                    do not add such variables into symbol table.
+                    
+                    An exception is Fortran, for which the first symbol
+                    in a common block will have address/offset 0.  */
                }
              else if (attr2 && (DW_UNSND (attr2) != 0))
                {
@@ -23195,6 +23283,16 @@ The value is the maximum depth to print.
                             NULL,
                             &setdebuglist, &showdebuglist);
 
+  add_setshow_zuinteger_cmd ("dwarf2-common",
+                             no_class, &dwarf2_common_debug, _("\
+Set debugging of dwarf2 common block handling."), _("\
+Show debugging of dwarf2 common block handling."), _("\
+When enabled (non-zero), common block variables are printed as they are\n\
+are relocated to their position in the common section."),
+                            NULL,
+                            NULL,
+                            &setdebuglist, &showdebuglist);
+
   add_setshow_boolean_cmd ("check-physname", no_class, &check_physname, _("\
 Set cross-checking of \"physname\" code against demangler."), _("\
 Show cross-checking of \"physname\" code against demangler."), _("\
--- symmisc.c.orig      2015-02-21 02:11:44.000000000 +0900
+++ symmisc.c   2016-03-27 18:46:17.000000000 +0900
@@ -626,6 +626,15 @@ print_symbol (void *args)
          fprintf_filtered (outfile, "optimized out");
          break;
 
+       case LOC_COMMON_BLOCK:
+         fprintf_filtered (outfile, "common block storage");
+
+         if (section)
+           fprintf_filtered (outfile, " section %s",
+                             bfd_section_name (section->the_bfd_section->owner,
+                                               section->the_bfd_section));
+         break;
+
        default:
          fprintf_filtered (outfile, "botched symbol class %x",
                            SYMBOL_CLASS (symbol));
--- psymtab.c.orig      2015-02-21 02:11:44.000000000 +0900
+++ psymtab.c   2016-03-27 18:13:25.000000000 +0900
@@ -915,6 +915,9 @@ print_partial_symbols (struct gdbarch *g
        case LABEL_DOMAIN:
          fputs_filtered ("label domain, ", outfile);
          break;
+       case COMMON_BLOCK_DOMAIN:
+         fputs_filtered ("common block domain, ", outfile);
+         break;
        default:
          fputs_filtered ("<invalid domain>, ", outfile);
          break;
---

          G Helffrich
          ghfbsd@gmail.com


[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 4056 bytes --]

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

* Re: [PATCH] gdb: dwarf2read: implement handling of variables in Fortran common block
  2016-03-30  5:32 [PATCH] gdb: dwarf2read: implement handling of variables in Fortran common block G Helffrich
@ 2016-04-11 22:01 ` Luis Machado
  0 siblings, 0 replies; 2+ messages in thread
From: Luis Machado @ 2016-04-11 22:01 UTC (permalink / raw)
  To: G Helffrich, gdb-patches

Your mailer seems to have mangled the patch somewhat, so it doesn't 
apply properly.

Could you please attach a diff or tweak the mailer settings?

I see this, for example:

+  attr =3D dwarf2_attr (die, DW_AT_name, cu);
+  name =3D dwarf2_compute_name (NULL, die, cu, 1);



On 03/30/2016 12:32 AM, G Helffrich wrote:
> This patch allows the gdb DWARF reader to handle variables located in Fortran common blocks.  This fixes 20 unexpected failures in the gdb.fortran testsuite with host, target and build triplet x86_64-apple-darwin13.4.0 with gfortran 4.9.2.
>
> gdb/ChangeLog:
>
> 2015-03-30  George Helffrich  <ghfbsd@gmail.com>
>
>          * dwarf2read.c (read_common_block): Relocate symbols in Fortran common
>            blocks properly.
>            (read_new_symbol_full): Don't discard zero-offset symbols in Fortran
>            common blocks.
>            (_initialize_dwarf2_read): Add debug diagnostic print for common
>            symbols.
>          * psymtab.c (print_partial_symbols): Recognize and print
>            COMMON_BLOCK_DOMAIN.
>          * symmisc.c (print_symbol):  Recognize and dump LOC_COMMON_BLOCK.
>
> ---
>
> --- dwarf2read.c.orig   2015-02-21 02:11:44.000000000 +0900
> +++ dwarf2read.c        2016-03-29 19:43:48.000000000 +0900
> @@ -84,6 +84,9 @@ static unsigned int dwarf2_read_debug =
>   /* When non-zero, dump DIEs after they are read in.  */
>   static unsigned int dwarf2_die_debug = 0;
>
> +/* When non-zero, report definition of common block variables.  */
> +static unsigned int dwarf2_common_debug = 0;
> +
>   /* When non-zero, cross-check physname against demangler.  */
>   static int check_physname = 0;
>
> @@ -13877,6 +13880,57 @@ static void
>   read_common_block (struct die_info *die, struct dwarf2_cu *cu)
>   {
>     struct attribute *attr;
> +  CORE_ADDR baseaddr;
> +  struct program_space *psp;
> +  struct minimal_symbol *msym = NULL;
> +  struct objfile *objfile = cu->objfile;
> +  struct gdbarch *gdbarch = get_objfile_arch (objfile);
> +  const char *name;
> +
> +  attr = dwarf2_attr (die, DW_AT_name, cu);
> +  name = dwarf2_compute_name (NULL, die, cu, 1);
> +  if (dwarf2_common_debug)
> +    {
> +      fprintf_unfiltered (gdb_stdlog,
> +                         "Read common blk %s (%s)\n",
> +                         DW_STRING(attr), name);
> +    }
> +  ALL_PSPACES (psp)
> +    ALL_PSPACE_OBJFILES (psp, objfile)
> +      if (objfile->flags & OBJF_MAINLINE) goto found;
> +found:
> +  if (objfile->flags & OBJF_MAINLINE)
> +    ALL_OBJFILE_MSYMBOLS (objfile, msym)
> +      {
> +        struct obj_section *section = MSYMBOL_OBJ_SECTION (objfile, msym);
> +
> +        if (0 == strcmp(MSYMBOL_LINKAGE_NAME (msym), name))
> +          {
> +            if (dwarf2_common_debug)
> +             {
> +               fprintf_unfiltered (gdb_stdlog, "  Found %s at ", name);
> +               fputs_filtered (paddress (gdbarch,
> +                                         MSYMBOL_VALUE_ADDRESS (objfile, msym)),
> +                                gdb_stdlog);
> +             }
> +            if (section && dwarf2_common_debug)
> +              {
> +                if (section->the_bfd_section != NULL)
> +                  fprintf_filtered (gdb_stdlog, " section %s",
> +                                    bfd_section_name (objfile->obfd,
> +                                                section->the_bfd_section));
> +                else
> +                 fprintf_filtered (gdb_stdlog, " spurious section %ld",
> +                                    (long) (section - objfile->sections));
> +             }
> +            if (dwarf2_common_debug)
> +             fprintf_unfiltered (gdb_stdlog, "\n");
> +
> +           /* Found base of common, now use it to relocate symbols in it */
> +            baseaddr = MSYMBOL_VALUE_ADDRESS (objfile, msym);
> +           break;
> +         }
> +      }
>
>     attr = dwarf2_attr (die, DW_AT_location, cu);
>     if (attr)
> @@ -13958,6 +14012,31 @@ read_common_block (struct die_info *die,
>                    else
>                      dwarf2_complex_location_expr_complaint ();
>                  }
> +
> +             if (dwarf2_common_debug)
> +               {
> +                 struct attribute *name = dwarf2_attr (child_die, DW_AT_name, cu);
> +                 fprintf_unfiltered (gdb_stdlog,
> +                                    "  Define common blk var %s at ",
> +                                    DW_STRING(name));
> +                 fputs_filtered (paddress (gdbarch,
> +                                           SYMBOL_VALUE_ADDRESS (sym)),
> +                                 gdb_stdlog);
> +                 fputs_filtered (" -> ", gdb_stdlog);
> +                 if (msym)
> +                   fputs_filtered (paddress (gdbarch,
> +                                             SYMBOL_VALUE_ADDRESS (sym)
> +                                             + baseaddr),
> +                                    gdb_stdlog);
> +                 else
> +                   fputs_filtered ("(unknown)", gdb_stdlog);
> +                 fputs_filtered ("\n", gdb_stdlog);
> +               }
> +
> +             /* Relocate symbol in common block */
> +             if (msym)
> +               SYMBOL_VALUE_ADDRESS (sym) += baseaddr;
> +
>              }
>          }
>
> @@ -18165,6 +18244,8 @@ new_symbol_full (struct die_info *die, s
>            attr = dwarf2_attr (die, DW_AT_location, cu);
>            if (attr)
>              {
> +             unsigned int fortran_common_symbol = 0;
> +
>                var_decode_location (attr, sym, cu);
>                attr2 = dwarf2_attr (die, DW_AT_external, cu);
>
> @@ -18172,16 +18253,23 @@ new_symbol_full (struct die_info *die, s
>                   scope by DW_TAG_common_block.  */
>                if (cu->language == language_fortran && die->parent
>                    && die->parent->tag == DW_TAG_common_block)
> -               attr2 = NULL;
> +               {
> +                 attr2 = NULL;
> +                 fortran_common_symbol = 1;
> +               }
>
>                if (SYMBOL_CLASS (sym) == LOC_STATIC
>                    && SYMBOL_VALUE_ADDRESS (sym) == 0
> +                 && !fortran_common_symbol
>                    && !dwarf2_per_objfile->has_section_at_zero)
>                  {
>                    /* When a static variable is eliminated by the linker,
>                       the corresponding debug information is not stripped
>                       out, but the variable address is set to null;
> -                    do not add such variables into symbol table.  */
> +                    do not add such variables into symbol table.
> +
> +                    An exception is Fortran, for which the first symbol
> +                    in a common block will have address/offset 0.  */
>                  }
>                else if (attr2 && (DW_UNSND (attr2) != 0))
>                  {
> @@ -23195,6 +23283,16 @@ The value is the maximum depth to print.
>                               NULL,
>                               &setdebuglist, &showdebuglist);
>
> +  add_setshow_zuinteger_cmd ("dwarf2-common",
> +                             no_class, &dwarf2_common_debug, _("\
> +Set debugging of dwarf2 common block handling."), _("\
> +Show debugging of dwarf2 common block handling."), _("\
> +When enabled (non-zero), common block variables are printed as they are\n\
> +are relocated to their position in the common section."),
> +                            NULL,
> +                            NULL,
> +                            &setdebuglist, &showdebuglist);
> +
>     add_setshow_boolean_cmd ("check-physname", no_class, &check_physname, _("\
>   Set cross-checking of \"physname\" code against demangler."), _("\
>   Show cross-checking of \"physname\" code against demangler."), _("\
> --- symmisc.c.orig      2015-02-21 02:11:44.000000000 +0900
> +++ symmisc.c   2016-03-27 18:46:17.000000000 +0900
> @@ -626,6 +626,15 @@ print_symbol (void *args)
>            fprintf_filtered (outfile, "optimized out");
>            break;
>
> +       case LOC_COMMON_BLOCK:
> +         fprintf_filtered (outfile, "common block storage");
> +
> +         if (section)
> +           fprintf_filtered (outfile, " section %s",
> +                             bfd_section_name (section->the_bfd_section->owner,
> +                                               section->the_bfd_section));
> +         break;
> +
>          default:
>            fprintf_filtered (outfile, "botched symbol class %x",
>                              SYMBOL_CLASS (symbol));
> --- psymtab.c.orig      2015-02-21 02:11:44.000000000 +0900
> +++ psymtab.c   2016-03-27 18:13:25.000000000 +0900
> @@ -915,6 +915,9 @@ print_partial_symbols (struct gdbarch *g
>          case LABEL_DOMAIN:
>            fputs_filtered ("label domain, ", outfile);
>            break;
> +       case COMMON_BLOCK_DOMAIN:
> +         fputs_filtered ("common block domain, ", outfile);
> +         break;
>          default:
>            fputs_filtered ("<invalid domain>, ", outfile);
>            break;
> ---
>
>            G Helffrich
>            ghfbsd@gmail.com
>

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

end of thread, other threads:[~2016-04-11 22:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-30  5:32 [PATCH] gdb: dwarf2read: implement handling of variables in Fortran common block G Helffrich
2016-04-11 22:01 ` Luis Machado

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).