public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
From: Tom de Vries <vries@sourceware.org>
To: gdb-cvs@sourceware.org
Subject: [binutils-gdb] [gdb/symtab] Fix segfault in dwarf2_per_objfile::symtab_set_p
Date: Fri,  8 Jul 2022 13:56:10 +0000 (GMT)	[thread overview]
Message-ID: <20220708135610.237B738582BE@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=3fa23bb5a5320dd82d32455036d59a026929fc2f

commit 3fa23bb5a5320dd82d32455036d59a026929fc2f
Author: Tom de Vries <tdevries@suse.de>
Date:   Fri Jul 8 15:56:06 2022 +0200

    [gdb/symtab] Fix segfault in dwarf2_per_objfile::symtab_set_p
    
    When running test-case gdb.cp/cpexprs-debug-types.exp with target board
    cc-with-debug-names, I run into:
    ...
    (gdb) print base::operator new^M
    ^M
    ^M
    Fatal signal: Segmentation fault^M
    ----- Backtrace -----^M
    0x57ea46 gdb_internal_backtrace_1^M
            /home/vries/gdb_versions/devel/src/gdb/bt-utils.c:122^M
    0x57eae9 _Z22gdb_internal_backtracev^M
            /home/vries/gdb_versions/devel/src/gdb/bt-utils.c:168^M
    0x75b8ad handle_fatal_signal^M
            /home/vries/gdb_versions/devel/src/gdb/event-top.c:946^M
    0x75ba19 handle_sigsegv^M
            /home/vries/gdb_versions/devel/src/gdb/event-top.c:1019^M
    0x7f795f46a8bf ???^M
    0x6d3cb1 _ZNK18dwarf2_per_objfile12symtab_set_pEPK18dwarf2_per_cu_data^M
            /home/vries/gdb_versions/devel/src/gdb/dwarf2/read.c:1515^M
    ...
    
    The problem is in this piece of code in dw2_debug_names_iterator::next:
    ...
            case DW_IDX_type_unit:
              /* Don't crash on bad data.  */
              if (ull >= per_bfd->tu_stats.nr_tus)
                {
                  complaint (_(".debug_names entry has bad TU index %s"
                               " [in module %s]"),
                             pulongest (ull),
                             objfile_name (objfile));
                  continue;
                }
              per_cu = per_bfd->get_cu (ull + per_bfd->tu_stats.nr_tus);
              break;
    ...
    
    The all_comp_units vector (which get_cu accesses) contains both CUs and TUs,
    with CUs first.
    
    So to get the nth TU we need the element at "nr_cus + n", but
    the code uses "nr_tus + n" instead.
    
    Fix this by using "nr_cus + n".
    
    Tested on x86_64-linux.
    
    Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29334

Diff:
---
 gdb/dwarf2/read.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 23fe5679cbd..9f92b420645 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -4991,7 +4991,11 @@ dw2_debug_names_iterator::next ()
 			 objfile_name (objfile));
 	      continue;
 	    }
-	  per_cu = per_bfd->get_cu (ull + per_bfd->tu_stats.nr_tus);
+	  {
+	    int nr_cus = (per_bfd->all_comp_units.size ()
+			  - per_bfd->tu_stats.nr_tus);
+	    per_cu = per_bfd->get_cu (nr_cus + ull);
+	  }
 	  break;
 	case DW_IDX_die_offset:
 	  /* In a per-CU index (as opposed to a per-module index), index


                 reply	other threads:[~2022-07-08 13:56 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220708135610.237B738582BE@sourceware.org \
    --to=vries@sourceware.org \
    --cc=gdb-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).