From patchwork Sun Jul 19 23:37:23 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Evans X-Patchwork-Id: 7743 Received: (qmail 45088 invoked by alias); 19 Jul 2015 23:37:27 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 45078 invoked by uid 89); 19 Jul 2015 23:37:27 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.2 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pd0-f201.google.com Received: from mail-pd0-f201.google.com (HELO mail-pd0-f201.google.com) (209.85.192.201) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Sun, 19 Jul 2015 23:37:25 +0000 Received: by pdav4 with SMTP id v4so14379397pda.0 for ; Sun, 19 Jul 2015 16:37:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:message-id:date:subject:from:to :content-type; bh=dfLNjbeAJ4QOb3K4r9l3ohk9HuZpH1RHshrdZvg93rk=; b=DqqtYYcaLKa9SdZUEUdoAHsq/uqzq+i7G2iEmJcQazCx2iyBuybBgUBrqpDlFqgKz4 jDjyJ55UIxv2O5w9gcp5IHr213oVkFGLYkk3zMpsV55jXLVNOKpCwGGaBMuPWENkZ7uX iSKoM8PAFCCpLlmStuQ62ZpgefRucdgG2rGlJJr/SYV+raXhNgan5BTOySW+nfEFrBhv agQrGFnwCu3sT0fmUTySEkpoHwSgH6R3apgcvl6NiJYEtz1PtjOGC4PCS0kumyHN2ZKC vNnsnyXd/M4PpB84tqhpxVZxWrF2wh1fPRdnRBqXqQITN+tPjR33/PkfZ//NgBSanZiE f5Zg== X-Gm-Message-State: ALoCoQkJlmkhODN3O8nZsXFYEZZcKXNQtpH7I04GDpu8DN26aObV6e1jwRlSoSPOGue7ZNA5aknoqF4/Q3YBUT8bNaCpAavPzl9k3TNJQqnHSbqe6BCWjvc10LDGK+sSBZf1EL6ZSsM1R71ik6RZ3QWMR396pbHUi6gwMCIMdb3NKaNE1WAmm74= MIME-Version: 1.0 X-Received: by 10.70.130.11 with SMTP id oa11mr8664819pdb.7.1437349043316; Sun, 19 Jul 2015 16:37:23 -0700 (PDT) Message-ID: <001a11c301ba256356051b42e72e@google.com> Date: Sun, 19 Jul 2015 23:37:23 +0000 Subject: [PATCH] Don't crash on dummy CUs From: Doug Evans To: gdb-patches@sourceware.org X-IsSubscribed: yes Hi. This patch fixes a crash when loading dummy CUs. Dummy CUs are used to add filler for the incremental linker, and consist of a CU header but no dies. 2015-07-19 Doug Evans * dwarf2read.c (dwarf2_per_cu_data): Add comment. (load_cu): Handle dummy CUs. (dw2_do_instantiate_symtab, process_queuef): Ditto. (dwarf2_fetch_die_loc_sect_off, dwarf2_fetch_constant_bytes): Ditto. testsuite/ * gdb.dwarf2/dw2-dummy-cu.S: New file. * gdb.dwarf2/dw2-dummy-cu.exp: New file. + +set GDBFLAGS $saved_gdbflags diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index f440956..24a4022 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -610,7 +610,8 @@ struct dwarf2_per_cu_data struct dwarf2_section_info *section; /* Set to non-NULL iff this CU is currently loaded. When it gets freed out - of the CU cache it gets reset to NULL again. */ + of the CU cache it gets reset to NULL again. This is left as NULL for + dummy CUs (a CU header, but nothing else). */ struct dwarf2_cu *cu; /* The corresponding objfile. @@ -2655,7 +2656,8 @@ load_cu (struct dwarf2_per_cu_data *per_cu) else load_full_comp_unit (per_cu, language_minimal); - gdb_assert (per_cu->cu != NULL); + if (per_cu->cu == NULL) + return; /* Dummy CU. */ dwarf2_find_base_address (per_cu->cu->dies, per_cu->cu); } @@ -2685,6 +2687,7 @@ dw2_do_instantiate_symtab (struct dwarf2_per_cu_data *per_cu) that may badly handle TUs, load all the TUs in that DWO as well. http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */ if (!per_cu->is_debug_types + && per_cu->cu != NULL && per_cu->cu->dwo_unit != NULL && dwarf2_per_objfile->index_table != NULL && dwarf2_per_objfile->index_table->version <= 7 @@ -7544,9 +7547,11 @@ process_queue (void) may load a new CU, adding it to the end of the queue. */ for (item = dwarf2_queue; item != NULL; dwarf2_queue = item = next_item) { - if (dwarf2_per_objfile->using_index - ? !item->per_cu->v.quick->compunit_symtab - : (item->per_cu->v.psymtab && !item->per_cu->v.psymtab->readin)) + if ((dwarf2_per_objfile->using_index + ? !item->per_cu->v.quick->compunit_symtab + : (item->per_cu->v.psymtab && !item->per_cu->v.psymtab->readin)) + /* Skip dummy CUs. */ + && item->per_cu->cu != NULL) { struct dwarf2_per_cu_data *per_cu = item->per_cu; unsigned int debug_print_threshold; @@ -20017,6 +20022,13 @@ dwarf2_fetch_die_loc_sect_off (sect_offset offset, if (per_cu->cu == NULL) load_cu (per_cu); cu = per_cu->cu; + if (cu == NULL) + { + /* We shouldn't get here for a dummy CU, but don't crash on the user. + Instead just throw an error, not much else we can do. */ + error (_("Dwarf Error: Dummy CU at 0x%x referenced in module %s"), + offset.sect_off, objfile_name (per_cu->objfile)); + } die = follow_die_offset (offset, per_cu->is_dwz, &cu); if (!die) @@ -20118,6 +20130,13 @@ dwarf2_fetch_constant_bytes (sect_offset offset, if (per_cu->cu == NULL) load_cu (per_cu); cu = per_cu->cu; + if (cu == NULL) + { + /* We shouldn't get here for a dummy CU, but don't crash on the user. + Instead just throw an error, not much else we can do. */ + error (_("Dwarf Error: Dummy CU at 0x%x referenced in module %s"), + offset.sect_off, objfile_name (per_cu->objfile)); + } die = follow_die_offset (offset, per_cu->is_dwz, &cu); if (!die) diff --git a/gdb/testsuite/gdb.dwarf2/dw2-dummy-cu.S b/gdb/testsuite/gdb.dwarf2/dw2-dummy-cu.S new file mode 100644 index 0000000..fa31561 --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/dw2-dummy-cu.S @@ -0,0 +1,33 @@ +/* Copyright 2015 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + + .text +main: + .4byte 0 +main_end: + + .section .debug_info + .4byte .Ldebug_info_end - 1f /* Length of Compilation Unit Info */ +1: + .2byte 0x2 /* DWARF version number */ + .4byte .Ldebug_abbrev0 /* Offset Into Abbrev. Section */ + .byte 0x4 /* Pointer Size (in bytes) */ + + /* Nothing else, this is a dummy die. */ +.Ldebug_info_end: + + .section .debug_abbrev +.Ldebug_abbrev0: + .byte 0x0 diff --git a/gdb/testsuite/gdb.dwarf2/dw2-dummy-cu.exp b/gdb/testsuite/gdb.dwarf2/dw2-dummy-cu.exp new file mode 100644 index 0000000..98120e4 --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/dw2-dummy-cu.exp @@ -0,0 +1,39 @@ +# Copyright 2015 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +load_lib dwarf.exp + +# This test can only be run on targets which support DWARF-2 and use gas. +if {![dwarf2_support]} { + return 0 +} + +standard_testfile .S +set executable ${testfile} + +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" object {}] != "" } { + return -1 +} + +set saved_gdbflags $GDBFLAGS +set GDBFLAGS "$GDBFLAGS -readnow" + +clean_restart $executable + +# Something simple to verify gdb didn't crash, and has read in whatever symbol +# info is there. +gdb_test "info fun main" "main_end"