This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PATCH: Add discriminator support to bfd, objdump and addr2line


Hi,

I have added a new interface bfd_find_nearest_line_discriminator() to
also return the discriminator (which was previously being ignored when
reading the dwarf), and also added support to print non-zero
discriminators along with the source position information from objdump
and addr2line.

Tested on x86_64-unknown-linux-gnu. Ok for trunk?

Thanks,
Teresa

2012-07-20  Teresa Johnson  <tejohnson@google.com>

        * bfd/bfd.c (bfd_find_nearest_line_discriminator): New macro.
        * bfd/coff-rs6000.c: Init _bfd_find_nearest_line_discriminator.
        * bfd/coff64-rs6000.c: Likewise.
        * bfd/dwarf2.c (struct line_info): Add discriminator field.
        (add_line_info): Fill in new discriminator field.
        (decode_line_info): Record discriminator information instead
        of ignoring it.
        (lookup_address_in_line_info_table): Return discriminator field if
        requested.
        (comp_unit_find_nearest_line): Add discriminator argument.
        (find_line): Likewise.
        (_bfd_dwarf2_find_nearest_line): Likewise.
        (_bfd_dwarf2_find_line): Likewise.
        * bfd/elf-bfd.h (_bfd_elf_find_nearest_line_discriminator): New.
        (_bfd_elf_find_line_discriminator): Likewise.
        (_bfd_generic_find_nearest_line_discriminator): Likewise. Defined.
        * bfd/elf.c (_bfd_elf_find_nearest_line): Change to a wrapper
        that invokes _bfd_elf_find_nearest_line_discriminator with correct
        arguments.
        (_bfd_elf_find_nearest_line_discriminator): New.
        (_bfd_elf_find_line): Change to a wrapper
        that invokes _bfd_elf_find_line_discriminator with correct
        arguments.
        (_bfd_elf_find_line_discriminator): New.
        * bfd/coffgen.c (coff_find_nearest_line_with_names): Handle
        new discriminator argument.
        * bfd/elf32-arm.c (elf32_arm_find_nearest_line): Likewise.
        * bfd/elf64-alpha.c (elf64_alpha_find_nearest_line): Likewise.
        * bfd/elfxx-mips.c (_bfd_mips_elf_find_nearest_line): Likewise.
        * bfd/mach-o.c (bfd_mach_o_find_nearest_line): Likewise.
        * bfd/libbfd-in.h (_bfd_dwarf2_find_nearest_line): Add discriminator
        argument.
        (_bfd_dwarf2_find_line): Likewise.
        (_bfd_generic_find_nearest_line_discriminator): New.
        * bfd/libbfd.c (_bfd_generic_find_nearest_line_discriminator): New.
        * bfd/bfd-in2.h: Regenerated.
        * bfd/libbfd.h: Likewise.
        * bfd/targets.c (BFD_JUMP_TABLE_SYMBOLS): Initialize
        _bfd_find_nearest_line_discriminator with
        _bfd_generic_find_nearest_line_discriminator.
        (bfd_target): Add _bfd_find_nearest_line_discriminator.
        * binutils/addr2line.c (find_address_in_section): Invoke
        bfd_find_nearest_line_discriminator to get the discriminator.
        (find_offset_in_section): Likewise.
        (translate_addresses): Print discriminator if it is non-zero.
        * binutils/objdump.c (show_line): Invoke
        bfd_find_nearest_line_discriminator to get the discriminator,
        and keep track of prev_discriminator. Print discriminator
        if it is non-zero.
        (disassemble_data): Initialize prev_discriminator.
        (dump_reloc_set): Invoke bfd_find_nearest_line_discriminator
        to get the discriminator, and keep track of last_discriminator.
        Print discriminator if it is non-zero.

Index: bfd/bfd-in2.h
===================================================================
RCS file: /cvs/src/src/bfd/bfd-in2.h,v
retrieving revision 1.582
diff -u -p -r1.582 bfd-in2.h
--- bfd/bfd-in2.h       18 Jul 2012 17:09:31 -0000      1.582
+++ bfd/bfd-in2.h       20 Jul 2012 20:46:40 -0000
@@ -5810,6 +5810,11 @@ bfd_boolean bfd_set_private_flags (bfd *
        BFD_SEND (abfd, _bfd_find_nearest_line, \
                  (abfd, sec, syms, off, file, func, line))

+#define bfd_find_nearest_line_discriminator(abfd, sec, syms, off, file, func, \
+                                            line, disc) \
+       BFD_SEND (abfd, _bfd_find_nearest_line_discriminator, \
+                 (abfd, sec, syms, off, file, func, line, disc))
+
 #define bfd_find_line(abfd, syms, sym, file, line) \
        BFD_SEND (abfd, _bfd_find_line, \
                  (abfd, syms, sym, file, line))
@@ -6191,6 +6196,7 @@ typedef struct bfd_target
   NAME##_bfd_is_target_special_symbol, \
   NAME##_get_lineno, \
   NAME##_find_nearest_line, \
+  _bfd_generic_find_nearest_line_discriminator, \
   _bfd_generic_find_line, \
   NAME##_find_inliner_info, \
   NAME##_bfd_make_debug_symbol, \
@@ -6214,6 +6220,9 @@ typedef struct bfd_target
   bfd_boolean (*_bfd_find_nearest_line)
     (bfd *, struct bfd_section *, struct bfd_symbol **, bfd_vma,
      const char **, const char **, unsigned int *);
+  bfd_boolean (*_bfd_find_nearest_line_discriminator)
+    (bfd *, struct bfd_section *, struct bfd_symbol **, bfd_vma,
+     const char **, const char **, unsigned int *, unsigned int *);
   bfd_boolean (*_bfd_find_line)
     (bfd *, struct bfd_symbol **, struct bfd_symbol *,
      const char **, unsigned int *);
Index: bfd/bfd.c
===================================================================
RCS file: /cvs/src/src/bfd/bfd.c,v
retrieving revision 1.121
diff -u -p -r1.121 bfd.c
--- bfd/bfd.c   14 May 2012 19:45:17 -0000      1.121
+++ bfd/bfd.c   20 Jul 2012 20:46:40 -0000
@@ -1424,6 +1424,11 @@ DESCRIPTION
 .       BFD_SEND (abfd, _bfd_find_nearest_line, \
 .                 (abfd, sec, syms, off, file, func, line))
 .
+.#define bfd_find_nearest_line_discriminator(abfd, sec, syms, off,
file, func, \
+.                                            line, disc) \
+.       BFD_SEND (abfd, _bfd_find_nearest_line_discriminator, \
+.                 (abfd, sec, syms, off, file, func, line, disc))
+.
 .#define bfd_find_line(abfd, syms, sym, file, line) \
 .       BFD_SEND (abfd, _bfd_find_line, \
 .                 (abfd, syms, sym, file, line))
Index: bfd/coff-rs6000.c
===================================================================
RCS file: /cvs/src/src/bfd/coff-rs6000.c,v
retrieving revision 1.105
diff -u -p -r1.105 coff-rs6000.c
--- bfd/coff-rs6000.c   13 Jul 2012 14:22:44 -0000      1.105
+++ bfd/coff-rs6000.c   20 Jul 2012 20:46:40 -0000
@@ -4118,6 +4118,7 @@ const bfd_target rs6000coff_vec =
     coff_bfd_is_target_special_symbol,
     coff_get_lineno,
     xcoff_find_nearest_line,
+    _bfd_generic_find_nearest_line_discriminator,
     _bfd_generic_find_line,
     coff_find_inliner_info,
     coff_bfd_make_debug_symbol,
@@ -4373,6 +4374,7 @@ const bfd_target pmac_xcoff_vec =
     coff_bfd_is_target_special_symbol,
     coff_get_lineno,
     xcoff_find_nearest_line,
+    _bfd_generic_find_nearest_line_discriminator,
     _bfd_generic_find_line,
     coff_find_inliner_info,
     coff_bfd_make_debug_symbol,
Index: bfd/coff64-rs6000.c
===================================================================
RCS file: /cvs/src/src/bfd/coff64-rs6000.c,v
retrieving revision 1.89
diff -u -p -r1.89 coff64-rs6000.c
--- bfd/coff64-rs6000.c 11 Jul 2011 15:03:04 -0000      1.89
+++ bfd/coff64-rs6000.c 20 Jul 2012 20:46:40 -0000
@@ -2710,6 +2710,7 @@ const bfd_target rs6000coff64_vec =
     coff_bfd_is_target_special_symbol,
     coff_get_lineno,
     coff_find_nearest_line,
+    _bfd_generic_find_nearest_line_discriminator,
     _bfd_generic_find_line,
     coff_find_inliner_info,
     coff_bfd_make_debug_symbol,
@@ -2967,6 +2968,7 @@ const bfd_target aix5coff64_vec =
     coff_bfd_is_target_special_symbol,
     coff_get_lineno,
     coff_find_nearest_line,
+    _bfd_generic_find_nearest_line_discriminator,
     _bfd_generic_find_line,
     coff_find_inliner_info,
     coff_bfd_make_debug_symbol,
Index: bfd/coffgen.c
===================================================================
RCS file: /cvs/src/src/bfd/coffgen.c,v
retrieving revision 1.83
diff -u -p -r1.83 coffgen.c
--- bfd/coffgen.c       2 Nov 2011 14:53:03 -0000       1.83
+++ bfd/coffgen.c       20 Jul 2012 20:46:40 -0000
@@ -2153,7 +2153,7 @@ coff_find_nearest_line_with_names (bfd *
   if (_bfd_dwarf2_find_nearest_line (abfd, debug_sections,
                                      section, symbols, offset,
                                     filename_ptr, functionname_ptr,
-                                    line_ptr, 0,
+                                    line_ptr, NULL, 0,
                                     &coff_data(abfd)->dwarf2_find_line_info))
     return TRUE;

Index: bfd/dwarf2.c
===================================================================
RCS file: /cvs/src/src/bfd/dwarf2.c,v
retrieving revision 1.148
diff -u -p -r1.148 dwarf2.c
--- bfd/dwarf2.c        16 May 2012 13:57:11 -0000      1.148
+++ bfd/dwarf2.c        20 Jul 2012 20:46:40 -0000
@@ -980,6 +980,7 @@ struct line_info
   char *filename;
   unsigned int line;
   unsigned int column;
+  unsigned int discriminator;
   unsigned char op_index;
   unsigned char end_sequence;          /* End of (sequential) code
sequence.  */
 };
@@ -1080,6 +1081,7 @@ add_line_info (struct line_info_table *t
               char *filename,
               unsigned int line,
               unsigned int column,
+              unsigned int discriminator,
               int end_sequence)
 {
   bfd_size_type amt = sizeof (struct line_info);
@@ -1095,6 +1097,7 @@ add_line_info (struct line_info_table *t
   info->op_index = op_index;
   info->line = line;
   info->column = column;
+  info->discriminator = discriminator;
   info->end_sequence = end_sequence;

   if (filename && filename[0])
@@ -1573,6 +1576,7 @@ decode_line_info (struct comp_unit *unit
       char * filename = table->num_files ? concat_filename (table, 1) : NULL;
       unsigned int line = 1;
       unsigned int column = 0;
+      unsigned int discriminator = 0;
       int is_stmt = lh.default_is_stmt;
       int end_sequence = 0;
       /* eraxxon@alumni.rice.edu: Against the DWARF2 specs, some
@@ -1607,8 +1611,9 @@ decode_line_info (struct comp_unit *unit
              line += lh.line_base + (adj_opcode % lh.line_range);
              /* Append row to matrix using current values.  */
              if (!add_line_info (table, address, op_index, filename,
-                                 line, column, 0))
+                                 line, column, discriminator, 0))
                goto line_fail;
+              discriminator = 0;
              if (address < low_pc)
                low_pc = address;
              if (address > high_pc)
@@ -1626,9 +1631,10 @@ decode_line_info (struct comp_unit *unit
                {
                case DW_LNE_end_sequence:
                  end_sequence = 1;
-                 if (!add_line_info (table, address, op_index, filename,
-                                     line, column, end_sequence))
+                 if (!add_line_info (table, address, op_index, filename, line,
+                                     column, discriminator, end_sequence))
                    goto line_fail;
+                  discriminator = 0;
                  if (address < low_pc)
                    low_pc = address;
                  if (address > high_pc)
@@ -1668,7 +1674,8 @@ decode_line_info (struct comp_unit *unit
                  table->num_files++;
                  break;
                case DW_LNE_set_discriminator:
-                 (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
+                 discriminator =
+                      read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
                  line_ptr += bytes_read;
                  break;
                case DW_LNE_HP_source_file_correlation:
@@ -1686,8 +1693,9 @@ decode_line_info (struct comp_unit *unit
              break;
            case DW_LNS_copy:
              if (!add_line_info (table, address, op_index,
-                                 filename, line, column, 0))
+                                 filename, line, column, discriminator, 0))
                goto line_fail;
+              discriminator = 0;
              if (address < low_pc)
                low_pc = address;
              if (address > high_pc)
@@ -1788,7 +1796,8 @@ static bfd_boolean
 lookup_address_in_line_info_table (struct line_info_table *table,
                                   bfd_vma addr,
                                   const char **filename_ptr,
-                                  unsigned int *linenumber_ptr)
+                                  unsigned int *linenumber_ptr,
+                                  unsigned int *discriminator_ptr)
 {
   struct line_sequence *seq = NULL;
   struct line_info *each_line;
@@ -1823,6 +1832,8 @@ lookup_address_in_line_info_table (struc
         {
           *filename_ptr = each_line->filename;
           *linenumber_ptr = each_line->line;
+          if (discriminator_ptr)
+            *discriminator_ptr = each_line->discriminator;
           return TRUE;
         }
     }
@@ -2552,6 +2563,7 @@ comp_unit_find_nearest_line (struct comp
                             const char **filename_ptr,
                             const char **functionname_ptr,
                             unsigned int *linenumber_ptr,
+                            unsigned int *discriminator_ptr,
                             struct dwarf2_debug *stash)
 {
   bfd_boolean line_p;
@@ -2592,7 +2604,8 @@ comp_unit_find_nearest_line (struct comp
     stash->inliner_chain = function;
   line_p = lookup_address_in_line_info_table (unit->line_table, addr,
                                              filename_ptr,
-                                             linenumber_ptr);
+                                             linenumber_ptr,
+                                             discriminator_ptr);
   return line_p || func_p;
 }
@@ -3308,6 +3321,7 @@ find_line (bfd *abfd,
           const char **filename_ptr,
           const char **functionname_ptr,
           unsigned int *linenumber_ptr,
+          unsigned int *discriminator_ptr,
           unsigned int addr_size,
           void **pinfo)
 {
@@ -3419,6 +3433,7 @@ find_line (bfd *abfd,
                                                   filename_ptr,
                                                   functionname_ptr,
                                                   linenumber_ptr,
+                                                  discriminator_ptr,
                                                   stash));
          if (found)
            goto done;
@@ -3512,6 +3527,7 @@ find_line (bfd *abfd,
                                                     filename_ptr,
                                                     functionname_ptr,
                                                     linenumber_ptr,
+                                                    discriminator_ptr,
                                                     stash));

          if ((bfd_vma) (stash->info_ptr - stash->sec_info_ptr)
@@ -3546,12 +3562,13 @@ _bfd_dwarf2_find_nearest_line (bfd *abfd
                               const char **filename_ptr,
                               const char **functionname_ptr,
                               unsigned int *linenumber_ptr,
+                               unsigned int *discriminator_ptr,
                               unsigned int addr_size,
                               void **pinfo)
 {
   return find_line (abfd, debug_sections, section, offset, NULL, symbols,
-                    filename_ptr, functionname_ptr, linenumber_ptr, addr_size,
-                   pinfo);
+                    filename_ptr, functionname_ptr, linenumber_ptr,
+                    discriminator_ptr, addr_size, pinfo);
 }

 /* The DWARF2 version of find_line.
@@ -3563,11 +3580,13 @@ _bfd_dwarf2_find_line (bfd *abfd,
                       asymbol *symbol,
                       const char **filename_ptr,
                       unsigned int *linenumber_ptr,
+                       unsigned int *discriminator_ptr,
                       unsigned int addr_size,
                       void **pinfo)
 {
   return find_line (abfd, dwarf_debug_sections, NULL, 0, symbol, symbols,
-                    filename_ptr, NULL, linenumber_ptr, addr_size, pinfo);
+                    filename_ptr, NULL, linenumber_ptr, discriminator_ptr,
+                    addr_size, pinfo);
 }

 bfd_boolean
Index: bfd/elf-bfd.h
===================================================================
RCS file: /cvs/src/src/bfd/elf-bfd.h,v
retrieving revision 1.342
diff -u -p -r1.342 elf-bfd.h
--- bfd/elf-bfd.h       4 Jun 2012 14:35:20 -0000       1.342
+++ bfd/elf-bfd.h       20 Jul 2012 20:46:40 -0000
@@ -1876,9 +1876,16 @@ extern bfd_boolean _bfd_elf_set_arch_mac
 extern bfd_boolean _bfd_elf_find_nearest_line
   (bfd *, asection *, asymbol **, bfd_vma, const char **, const char **,
    unsigned int *);
+extern bfd_boolean _bfd_elf_find_nearest_line_discriminator
+  (bfd *, asection *, asymbol **, bfd_vma, const char **, const char **,
+   unsigned int *, unsigned int *);
 extern bfd_boolean _bfd_elf_find_line
   (bfd *, asymbol **, asymbol *, const char **, unsigned int *);
+extern bfd_boolean _bfd_elf_find_line_discriminator
+  (bfd *, asymbol **, asymbol *, const char **, unsigned int *,
unsigned int *);
 #define _bfd_generic_find_line _bfd_elf_find_line
+#define _bfd_generic_find_nearest_line_discriminator \
+        _bfd_elf_find_nearest_line_discriminator
 extern bfd_boolean _bfd_elf_find_inliner_info
   (bfd *, const char **, const char **, unsigned int *);
 #define _bfd_elf_read_minisymbols _bfd_generic_read_minisymbols
Index: bfd/elf.c
===================================================================
RCS file: /cvs/src/src/bfd/elf.c,v
retrieving revision 1.567
diff -u -p -r1.567 elf.c
--- bfd/elf.c   4 Jul 2012 00:29:51 -0000       1.567
+++ bfd/elf.c   20 Jul 2012 20:46:41 -0000
@@ -7567,6 +7567,23 @@ _bfd_elf_find_nearest_line (bfd *abfd,
                            const char **functionname_ptr,
                            unsigned int *line_ptr)
 {
+  return _bfd_elf_find_nearest_line_discriminator (abfd, section, symbols,
+                                                   offset, filename_ptr,
+                                                   functionname_ptr,
+                                                   line_ptr,
+                                                   NULL);
+}
+
+bfd_boolean
+_bfd_elf_find_nearest_line_discriminator (bfd *abfd,
+                                          asection *section,
+                                          asymbol **symbols,
+                                          bfd_vma offset,
+                                          const char **filename_ptr,
+                                          const char **functionname_ptr,
+                                          unsigned int *line_ptr,
+                                          unsigned int *discriminator_ptr)
+{
   bfd_boolean found;

   if (_bfd_dwarf1_find_nearest_line (abfd, section, symbols, offset,
@@ -7584,7 +7601,7 @@ _bfd_elf_find_nearest_line (bfd *abfd,
   if (_bfd_dwarf2_find_nearest_line (abfd, dwarf_debug_sections,
                                      section, symbols, offset,
                                     filename_ptr, functionname_ptr,
-                                    line_ptr, 0,
+                                    line_ptr, discriminator_ptr, 0,
                                     &elf_tdata (abfd)->dwarf2_find_line_info))
     {
       if (!*functionname_ptr)
@@ -7620,8 +7637,19 @@ bfd_boolean
 _bfd_elf_find_line (bfd *abfd, asymbol **symbols, asymbol *symbol,
                    const char **filename_ptr, unsigned int *line_ptr)
 {
+  return _bfd_elf_find_line_discriminator (abfd, symbols, symbol,
+                                          filename_ptr, line_ptr,
+                                           NULL);
+}
+
+bfd_boolean
+_bfd_elf_find_line_discriminator (bfd *abfd, asymbol **symbols,
asymbol *symbol,
+                                  const char **filename_ptr,
+                                  unsigned int *line_ptr,
+                                  unsigned int *discriminator_ptr)
+{
   return _bfd_dwarf2_find_line (abfd, symbols, symbol,
-                               filename_ptr, line_ptr, 0,
+                               filename_ptr, line_ptr, discriminator_ptr, 0,
                                &elf_tdata (abfd)->dwarf2_find_line_info);
 }

Index: bfd/elf32-arm.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-arm.c,v
retrieving revision 1.296
diff -u -p -r1.296 elf32-arm.c
--- bfd/elf32-arm.c     29 Jun 2012 15:20:30 -0000      1.296
+++ bfd/elf32-arm.c     20 Jul 2012 20:46:41 -0000
@@ -12886,7 +12886,7 @@ elf32_arm_find_nearest_line (bfd *
   if (_bfd_dwarf2_find_nearest_line (abfd, dwarf_debug_sections,
                                      section, symbols, offset,
                                     filename_ptr, functionname_ptr,
-                                    line_ptr, 0,
+                                    line_ptr, NULL, 0,
                                     & elf_tdata (abfd)->dwarf2_find_line_info))
     {
       if (!*functionname_ptr)
Index: bfd/elf64-alpha.c
===================================================================
RCS file: /cvs/src/src/bfd/elf64-alpha.c,v
retrieving revision 1.186
diff -u -p -r1.186 elf64-alpha.c
--- bfd/elf64-alpha.c   13 Jul 2012 14:22:47 -0000      1.186
+++ bfd/elf64-alpha.c   20 Jul 2012 20:46:41 -0000
@@ -1452,7 +1452,7 @@ elf64_alpha_find_nearest_line (bfd *abfd
   if (_bfd_dwarf2_find_nearest_line (abfd, dwarf_debug_sections,
                                      section, symbols, offset,
                                     filename_ptr, functionname_ptr,
-                                    line_ptr, 0,
+                                    line_ptr, NULL, 0,
                                     &elf_tdata (abfd)->dwarf2_find_line_info))
     return TRUE;

Index: bfd/elfxx-mips.c
===================================================================
RCS file: /cvs/src/src/bfd/elfxx-mips.c,v
retrieving revision 1.308
diff -u -p -r1.308 elfxx-mips.c
--- bfd/elfxx-mips.c    13 Jul 2012 14:22:48 -0000      1.308
+++ bfd/elfxx-mips.c    20 Jul 2012 20:46:42 -0000
@@ -11709,7 +11709,7 @@ _bfd_mips_elf_find_nearest_line (bfd *ab
   if (_bfd_dwarf2_find_nearest_line (abfd, dwarf_debug_sections,
                                      section, symbols, offset,
                                     filename_ptr, functionname_ptr,
-                                    line_ptr, ABI_64_P (abfd) ? 8 : 0,
+                                    line_ptr, NULL, ABI_64_P (abfd) ? 8 : 0,
                                     &elf_tdata (abfd)->dwarf2_find_line_info))
     return TRUE;

Index: bfd/libbfd-in.h
===================================================================
RCS file: /cvs/src/src/bfd/libbfd-in.h,v
retrieving revision 1.98
diff -u -p -r1.98 libbfd-in.h
--- bfd/libbfd-in.h     14 May 2012 19:45:19 -0000      1.98
+++ bfd/libbfd-in.h     20 Jul 2012 20:46:42 -0000
@@ -540,16 +540,21 @@ extern const struct dwarf_debug_section
 /* Find the nearest line using DWARF 2 debugging information.  */
 extern bfd_boolean _bfd_dwarf2_find_nearest_line
   (bfd *, const struct dwarf_debug_section *, asection *, asymbol **, bfd_vma,
-   const char **, const char **, unsigned int *, unsigned int, void **);
+   const char **, const char **, unsigned int *, unsigned int *, unsigned int,
+   void **);

 /* Find the line using DWARF 2 debugging information.  */
 extern bfd_boolean _bfd_dwarf2_find_line
   (bfd *, asymbol **, asymbol *, const char **,
-   unsigned int *, unsigned int, void **);
+   unsigned int *, unsigned int *, unsigned int, void **);

 bfd_boolean _bfd_generic_find_line
   (bfd *, asymbol **, asymbol *, const char **, unsigned int *);

+bfd_boolean _bfd_generic_find_nearest_line_discriminator
+  (bfd *, asection *, asymbol **, bfd_vma, const char **, const char **,
+   unsigned int *, unsigned int *);
+
 /* Find inliner info after calling bfd_find_nearest_line. */
 extern bfd_boolean _bfd_dwarf2_find_inliner_info
   (bfd *, const char **, const char **, unsigned int *, void **);
Index: bfd/libbfd.c
===================================================================
RCS file: /cvs/src/src/bfd/libbfd.c,v
retrieving revision 1.57
diff -u -p -r1.57 libbfd.c
--- bfd/libbfd.c        7 May 2011 13:48:50 -0000       1.57
+++ bfd/libbfd.c        20 Jul 2012 20:46:42 -0000
@@ -1118,6 +1118,19 @@ _bfd_generic_find_line (bfd *abfd ATTRIB
 }

 bfd_boolean
+_bfd_generic_find_nearest_line_discriminator (bfd *abfd ATTRIBUTE_UNUSED,
+                                              asection *section
ATTRIBUTE_UNUSED,
+                                              asymbol **symbols
ATTRIBUTE_UNUSED,
+                                              bfd_vma offset ATTRIBUTE_UNUSED,
+                                              const char
**filename_ptr ATTRIBUTE_UNUSED,
+                                              const char
**functionname_ptr ATTRIBUTE_UNUSED,
+                                              unsigned int *line_ptr
ATTRIBUTE_UNUSED,
+                                              unsigned int
*discriminator_ptr ATTRIBUTE_UNUSED)
+{
+  return FALSE;
+}
+
+bfd_boolean
 _bfd_generic_init_private_section_data (bfd *ibfd ATTRIBUTE_UNUSED,
                                        asection *isec ATTRIBUTE_UNUSED,
                                        bfd *obfd ATTRIBUTE_UNUSED,
Index: bfd/libbfd.h
===================================================================
RCS file: /cvs/src/src/bfd/libbfd.h,v
retrieving revision 1.278
diff -u -p -r1.278 libbfd.h
--- bfd/libbfd.h        13 Jul 2012 15:47:23 -0000      1.278
+++ bfd/libbfd.h        20 Jul 2012 20:46:42 -0000
@@ -545,16 +545,21 @@ extern const struct dwarf_debug_section
 /* Find the nearest line using DWARF 2 debugging information.  */
 extern bfd_boolean _bfd_dwarf2_find_nearest_line
   (bfd *, const struct dwarf_debug_section *, asection *, asymbol **, bfd_vma,
-   const char **, const char **, unsigned int *, unsigned int, void **);
+   const char **, const char **, unsigned int *, unsigned int *, unsigned int,
+   void **);

 /* Find the line using DWARF 2 debugging information.  */
 extern bfd_boolean _bfd_dwarf2_find_line
   (bfd *, asymbol **, asymbol *, const char **,
-   unsigned int *, unsigned int, void **);
+   unsigned int *, unsigned int *, unsigned int, void **);

 bfd_boolean _bfd_generic_find_line
   (bfd *, asymbol **, asymbol *, const char **, unsigned int *);

+bfd_boolean _bfd_generic_find_nearest_line_discriminator
+  (bfd *, asection *, asymbol **, bfd_vma, const char **, const char **,
+   unsigned int *, unsigned int *);
+
 /* Find inliner info after calling bfd_find_nearest_line. */
 extern bfd_boolean _bfd_dwarf2_find_inliner_info
   (bfd *, const char **, const char **, unsigned int *, void **);
Index: bfd/mach-o.c
===================================================================
RCS file: /cvs/src/src/bfd/mach-o.c,v
retrieving revision 1.102
diff -u -p -r1.102 mach-o.c
--- bfd/mach-o.c        23 Feb 2012 16:29:55 -0000      1.102
+++ bfd/mach-o.c        20 Jul 2012 20:46:42 -0000
@@ -4836,7 +4836,7 @@ bfd_mach_o_find_nearest_line (bfd *abfd,
   if (_bfd_dwarf2_find_nearest_line (abfd, dwarf_debug_sections,
                                     section, symbols, offset,
                                     filename_ptr, functionname_ptr,
-                                    line_ptr, 0,
+                                    line_ptr, NULL, 0,
                                     &mdata->dwarf2_find_line_info))
     return TRUE;
   return FALSE;
Index: bfd/targets.c
===================================================================
RCS file: /cvs/src/src/bfd/targets.c,v
retrieving revision 1.216
diff -u -p -r1.216 targets.c
--- bfd/targets.c       14 May 2012 19:45:20 -0000      1.216
+++ bfd/targets.c       20 Jul 2012 20:46:42 -0000
@@ -369,6 +369,7 @@ BFD_JUMP_TABLE macros.
 .  NAME##_bfd_is_target_special_symbol, \
 .  NAME##_get_lineno, \
 .  NAME##_find_nearest_line, \
+.  _bfd_generic_find_nearest_line_discriminator, \
 .  _bfd_generic_find_line, \
 .  NAME##_find_inliner_info, \
 .  NAME##_bfd_make_debug_symbol, \
@@ -392,6 +393,9 @@ BFD_JUMP_TABLE macros.
 .  bfd_boolean (*_bfd_find_nearest_line)
 .    (bfd *, struct bfd_section *, struct bfd_symbol **, bfd_vma,
 .     const char **, const char **, unsigned int *);
+.  bfd_boolean (*_bfd_find_nearest_line_discriminator)
+.    (bfd *, struct bfd_section *, struct bfd_symbol **, bfd_vma,
+.     const char **, const char **, unsigned int *, unsigned int *);
 .  bfd_boolean (*_bfd_find_line)
 .    (bfd *, struct bfd_symbol **, struct bfd_symbol *,
 .     const char **, unsigned int *);
Index: binutils/addr2line.c
===================================================================
RCS file: /cvs/src/src/binutils/addr2line.c,v
retrieving revision 1.41
diff -u -p -r1.41 addr2line.c
--- binutils/addr2line.c        1 Jun 2012 01:04:29 -0000       1.41
+++ binutils/addr2line.c        20 Jul 2012 20:46:42 -0000
@@ -139,6 +139,7 @@ static bfd_vma pc;
 static const char *filename;
 static const char *functionname;
 static unsigned int line;
+static unsigned int discriminator;
 static bfd_boolean found;

 /* Look for an address in a section.  This is called via
@@ -165,8 +166,9 @@ find_address_in_section (bfd *abfd, asec
   if (pc >= vma + size)
     return;

-  found = bfd_find_nearest_line (abfd, section, syms, pc - vma,
-                                &filename, &functionname, &line);
+  found = bfd_find_nearest_line_discriminator (abfd, section, syms, pc - vma,
+                                               &filename, &functionname,
+                                               &line, &discriminator);
 }

 /* Look for an offset in a section.  This is directly called.  */
@@ -186,8 +188,9 @@ find_offset_in_section (bfd *abfd, asect
   if (pc >= size)
     return;

-  found = bfd_find_nearest_line (abfd, section, syms, pc,
-                                &filename, &functionname, &line);
+  found = bfd_find_nearest_line_discriminator (abfd, section, syms, pc,
+                                               &filename, &functionname,
+                                               &line, &discriminator);
 }

 /* Read hexadecimal addresses from stdin, translate into
@@ -294,7 +297,12 @@ translate_addresses (bfd *abfd, asection

               printf ("%s:", filename ? filename : "??");
              if (line != 0)
-               printf ("%u\n", line);
+                {
+                  if (discriminator != 0)
+                    printf ("%u (discriminator %u)\n", line, discriminator);
+                  else
+                    printf ("%u\n", line);
+                }
              else
                printf ("?\n");
               if (!unwind_inlines)
Index: binutils/objdump.c
===================================================================
RCS file: /cvs/src/src/binutils/objdump.c,v
retrieving revision 1.194
diff -u -p -r1.194 objdump.c
--- binutils/objdump.c  14 May 2012 02:39:57 -0000      1.194
+++ binutils/objdump.c  20 Jul 2012 20:46:42 -0000
@@ -1086,6 +1086,7 @@ objdump_symbol_at_address (bfd_vma vma,

 static char *prev_functionname;
 static unsigned int prev_line;
+static unsigned int prev_discriminator;

 /* We keep a list of all files that we have seen when doing a
    disassembly with source, so that we know how much of the file to
@@ -1312,13 +1313,15 @@ show_line (bfd *abfd, asection *section,
   const char *filename;
   const char *functionname;
   unsigned int linenumber;
+  unsigned int discriminator;
   bfd_boolean reloc;

   if (! with_line_numbers && ! with_source_code)
     return;

-  if (! bfd_find_nearest_line (abfd, section, syms, addr_offset, &filename,
-                              &functionname, &linenumber))
+  if (! bfd_find_nearest_line_discriminator (abfd, section, syms, addr_offset,
+                                             &filename, &functionname,
+                                             &linenumber, &discriminator))
     return;

   if (filename != NULL && *filename == '\0')
@@ -1370,8 +1373,15 @@ show_line (bfd *abfd, asection *section,
          && (prev_functionname == NULL
              || strcmp (functionname, prev_functionname) != 0))
        printf ("%s():\n", functionname);
-      if (linenumber > 0 && linenumber != prev_line)
-       printf ("%s:%u\n", filename == NULL ? "???" : filename, linenumber);
+      if (linenumber > 0 && (linenumber != prev_line ||
+                             (discriminator != prev_discriminator)))
+        {
+          if (discriminator > 0)
+            printf ("%s:%u (discriminator %u)\n", filename == NULL ?
"???" : filename,
+                    linenumber, discriminator);
+          else
+            printf ("%s:%u\n", filename == NULL ? "???" : filename,
linenumber);
+        }
     }

   if (with_source_code
@@ -1423,6 +1433,9 @@ show_line (bfd *abfd, asection *section,

   if (linenumber > 0 && linenumber != prev_line)
     prev_line = linenumber;
+
+  if (discriminator != prev_discriminator)
+    prev_discriminator = discriminator;
 }

 /* Pseudo FILE object for strings.  */
@@ -2115,6 +2128,7 @@ disassemble_data (bfd *abfd)
   print_files = NULL;
   prev_functionname = NULL;
   prev_line = -1;
+  prev_discriminator = 0;

   /* We make a copy of syms to sort.  We don't want to sort syms
      because that will screw up the relocs.  */
@@ -2895,6 +2909,7 @@ dump_reloc_set (bfd *abfd, asection *sec
   arelent **p;
   char *last_filename, *last_functionname;
   unsigned int last_line;
+  unsigned int last_discriminator;

   /* Get column headers lined up reasonably.  */
   {
@@ -2913,12 +2928,14 @@ dump_reloc_set (bfd *abfd, asection *sec
   last_filename = NULL;
   last_functionname = NULL;
   last_line = 0;
+  last_discriminator = 0;

   for (p = relpp; relcount && *p != NULL; p++, relcount--)
     {
       arelent *q = *p;
       const char *filename, *functionname;
       unsigned int linenumber;
+      unsigned int discriminator;
       const char *sym_name;
       const char *section_name;
       bfd_vma addend2 = 0;
@@ -2932,8 +2949,9 @@ dump_reloc_set (bfd *abfd, asection *sec

       if (with_line_numbers
          && sec != NULL
-         && bfd_find_nearest_line (abfd, sec, syms, q->address,
-                                   &filename, &functionname, &linenumber))
+         && bfd_find_nearest_line_discriminator (abfd, sec, syms, q->address,
+                                                  &filename, &functionname,
+                                                  &linenumber, &discriminator))
        {
          if (functionname != NULL
              && (last_functionname == NULL
@@ -2949,10 +2967,16 @@ dump_reloc_set (bfd *abfd, asection *sec
              && (linenumber != last_line
                  || (filename != NULL
                      && last_filename != NULL
-                     && filename_cmp (filename, last_filename) != 0)))
+                     && filename_cmp (filename, last_filename) != 0)
+                  || (discriminator != last_discriminator)))
            {
-             printf ("%s:%u\n", filename == NULL ? "???" : filename,
linenumber);
+              if (discriminator > 0)
+                printf ("%s:%u\n", filename == NULL ? "???" :
filename, linenumber);
+              else
+                printf ("%s:%u (discriminator %u)\n", filename ==
NULL ? "???" : filename,
+                        linenumber, discriminator);
              last_line = linenumber;
+             last_discriminator = discriminator;
              if (last_filename != NULL)
                free (last_filename);
              if (filename == NULL)


--
Teresa Johnson | Software Engineer | tejohnson@google.com | 408-460-2413


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]