From patchwork Fri Mar 20 11:36:01 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Wingo X-Patchwork-Id: 5717 Received: (qmail 120004 invoked by alias); 20 Mar 2015 11:36:11 -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 119994 invoked by uid 89); 20 Mar 2015 11:36:10 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_NEUTRAL autolearn=ham version=3.3.2 X-HELO: sasl.smtp.pobox.com Received: from pb-sasl1.int.icgroup.com (HELO sasl.smtp.pobox.com) (208.72.237.25) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 20 Mar 2015 11:36:08 +0000 Received: from sasl.smtp.pobox.com (unknown [127.0.0.1]) by pb-sasl1.pobox.com (Postfix) with ESMTP id 75DFD3C40F for ; Fri, 20 Mar 2015 07:36:06 -0400 (EDT) Received: from pb-sasl1.int.icgroup.com (unknown [127.0.0.1]) by pb-sasl1.pobox.com (Postfix) with ESMTP id 6E0C83C40E for ; Fri, 20 Mar 2015 07:36:06 -0400 (EDT) Received: from rusty (unknown [88.160.190.192]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by pb-sasl1.pobox.com (Postfix) with ESMTPSA id 7D4683C40D for ; Fri, 20 Mar 2015 07:36:04 -0400 (EDT) From: Andy Wingo To: gdb-patches@sourceware.org Subject: [PATCH][PR symtab/18148] Properly intern constants into psymtab Date: Fri, 20 Mar 2015 12:36:01 +0100 Message-ID: <87sicz6gv2.fsf@igalia.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) MIME-Version: 1.0 Content-Disposition: inline; filename=0001-Properly-intern-constants-into-psymtab.patch X-Pobox-Relay-ID: 4B7884BC-CEF5-11E4-9504-EA766A2A9587-02397024!pb-sasl1.pobox.com X-IsSubscribed: yes From 16de9f67e56b5b58ff7923db0d6505d61c766124 Mon Sep 17 00:00:00 2001 From: Andy Wingo Date: Fri, 20 Mar 2015 11:50:00 +0100 Subject: [PATCH] Properly intern constants into psymtab Variables with a DW_AT_const_value but without a DW_AT_location were not getting added to the partial symbol table. They are added to the full symbol table, however, when the compilation unit's psymtabs are expanded. Before: (gdb) p one No symbol "one" in current context. (gdb) mt flush-symbol-cache (gdb) mt expand one.c (gdb) p one $1 = 1 After: (gdb) p one $1 = 1 To the user it's pretty strange, as depending on whether tab completion has forced expansion of all CUs or not the lookup might succeed, or not if the failure was already added to the symbol cache. This commit simply makes sure to add constants to the partial symbol tables. gdb/testsuite/ChangeLog: PR symtab/18148 * gdb.dwarf2/dw2-intercu.S (one, two): Add variables that have a const_value but not a location. * gdb.dwarf2/dw2-intercu.exp: Add tests that constants without location defined in non-main CUs are visible. gdb/ChangeLog: PR symtab/18148 * dwarf2read.c (struct partial_die_info): Add has_const_value member. (add_partial_symbol): Don't punt on symbols that have const_value attributes. (read_partial_die): Detect DW_AT_const_value. --- gdb/ChangeLog | 9 ++++ gdb/dwarf2read.c | 17 +++++-- gdb/testsuite/ChangeLog | 8 ++++ gdb/testsuite/gdb.dwarf2/dw2-intercu.S | 79 ++++++++++++++++++++++++++++++++ gdb/testsuite/gdb.dwarf2/dw2-intercu.exp | 5 ++ 5 files changed, 115 insertions(+), 3 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index bd49503..a9eeaf0 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,12 @@ +2015-03-20 Andy Wingo + + PR symtab/18148 + * dwarf2read.c (struct partial_die_info): Add has_const_value + member. + (add_partial_symbol): Don't punt on symbols that have const_value + attributes. + (read_partial_die): Detect DW_AT_const_value. + 2015-03-05 Andy Wingo * guile/scm-symbol.c (gdbscm_lookup_symbol): Don't error if there diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index c185d51..c98a619 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -1105,6 +1105,9 @@ struct partial_die_info /* Flag set if the DIE has a byte_size attribute. */ unsigned int has_byte_size : 1; + /* Flag set if the DIE has a DW_AT_const_value attribute. */ + unsigned int has_const_value : 1; + /* Flag set if any of the DIE's children are template arguments. */ unsigned int has_template_arguments : 1; @@ -6956,19 +6959,24 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu) } else { - /* Static Variable. Skip symbols without location descriptors. */ - if (pdi->d.locdesc == NULL) + int has_loc = pdi->d.locdesc != NULL; + + /* Static Variable. Skip symbols whose value we cannot know (those + without location descriptors or constant values). */ + if (!has_loc && !pdi->has_const_value) { xfree (built_actual_name); return; } + /* prim_record_minimal_symbol (actual_name, addr + baseaddr, mst_file_data, objfile); */ add_psymbol_to_list (actual_name, strlen (actual_name), built_actual_name != NULL, VAR_DOMAIN, LOC_STATIC, &objfile->static_psymbols, - 0, addr + baseaddr, + 0, + has_loc ? addr + baseaddr : (CORE_ADDR) 0, cu->language, objfile); } break; @@ -15834,6 +15842,9 @@ read_partial_die (const struct die_reader_specs *reader, case DW_AT_byte_size: part_die->has_byte_size = 1; break; + case DW_AT_const_value: + part_die->has_const_value = 1; + break; case DW_AT_calling_convention: /* DWARF doesn't provide a way to identify a program's source-level entry point. DW_AT_calling_convention attributes are only meant diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 52a60f8..fbc4f9a 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,11 @@ +2015-03-20 Andy Wingo + + PR symtab/18148 + * gdb.dwarf2/dw2-intercu.S (one, two): Add variables that have a + const_value but not a location. + * gdb.dwarf2/dw2-intercu.exp: Add tests that constants without + location defined in non-main CUs are visible. + 2015-03-06 Andy Wingo * gdb.guile/scm-frame-unwinder.exp: diff --git a/gdb/testsuite/gdb.dwarf2/dw2-intercu.S b/gdb/testsuite/gdb.dwarf2/dw2-intercu.S index b155e0b..c033e4d 100644 --- a/gdb/testsuite/gdb.dwarf2/dw2-intercu.S +++ b/gdb/testsuite/gdb.dwarf2/dw2-intercu.S @@ -64,6 +64,24 @@ func_cu1: .byte 1 /* DW_AT_frame_base: length */ .byte 0x55 /* DW_AT_frame_base: DW_OP_reg5 */ + /* This type is named "int1" and not "int" to ensure it is unique, + and thus we can easily ensure we expand this CU and not some + other CU with "int". */ +.Ltype_int1_in_cu1: + .uleb128 3 /* Abbrev: DW_TAG_base_type */ + .ascii "int1\0" /* DW_AT_name */ + .byte 4 /* DW_AT_byte_size */ + .byte 5 /* DW_AT_encoding */ + +.Ltype_const_int1_in_cu1: + .uleb128 4 /* Abbrev: DW_TAG_const_type */ + .4byte .Ltype_int1_in_cu1-.Lcu1_begin /* DW_AT_type */ + + .uleb128 5 /* Abbrev: DW_TAG_variable */ + .ascii "one\0" /* DW_AT_name */ + .4byte .Ltype_const_int1_in_cu1-.Lcu1_begin /* DW_AT_type */ + .byte 1 /* DW_AT_const_value */ + .byte 0 /* End of children of CU */ .Lcu1_end: @@ -92,6 +110,15 @@ func_cu1: .byte 4 /* DW_AT_byte_size */ .byte 5 /* DW_AT_encoding */ +.Ltype_const_int2_in_cu2: + .uleb128 3 /* Abbrev: DW_TAG_const_type */ + .4byte .Ltype_int2_in_cu2-.Lcu2_begin /* DW_AT_type */ + + .uleb128 4 /* Abbrev: DW_TAG_variable */ + .ascii "two\0" /* DW_AT_name */ + .4byte .Ltype_const_int2_in_cu2-.Lcu2_begin /* DW_AT_type */ + .byte 2 /* DW_AT_const_value */ + .byte 0 /* End of children of CU */ .Lcu2_end: @@ -139,6 +166,38 @@ func_cu1: .byte 0x0 /* Terminator */ .byte 0x0 /* Terminator */ + .uleb128 3 /* Abbrev code */ + .uleb128 0x24 /* DW_TAG_base_type */ + .byte 0 /* has_children */ + .uleb128 0x3 /* DW_AT_name */ + .uleb128 0x8 /* DW_FORM_string */ + .uleb128 0xb /* DW_AT_byte_size */ + .uleb128 0xb /* DW_FORM_data1 */ + .uleb128 0x3e /* DW_AT_encoding */ + .uleb128 0xb /* DW_FORM_data1 */ + .byte 0x0 /* Terminator */ + .byte 0x0 /* Terminator */ + + .uleb128 4 /* Abbrev code */ + .uleb128 0x26 /* DW_TAG_const_type */ + .byte 0x0 /* DW_children_no */ + .uleb128 0x49 /* DW_AT_type */ + .uleb128 0x13 /* DW_FORM_ref4 */ + .byte 0x0 /* Terminator */ + .byte 0x0 /* Terminator */ + + .uleb128 5 /* Abbrev code */ + .uleb128 0x34 /* DW_TAG_variable */ + .byte 0x0 /* DW_children_no */ + .uleb128 0x3 /* DW_AT_name */ + .uleb128 0x8 /* DW_FORM_string */ + .uleb128 0x49 /* DW_AT_type */ + .uleb128 0x13 /* DW_FORM_ref4 */ + .uleb128 0x1c /* DW_AT_const_value */ + .uleb128 0xb /* DW_FORM_data1 */ + .byte 0x0 /* Terminator */ + .byte 0x0 /* Terminator */ + .byte 0x0 /* Terminator */ .byte 0x0 /* Terminator */ @@ -167,6 +226,26 @@ func_cu1: .byte 0x0 /* Terminator */ .byte 0x0 /* Terminator */ + .uleb128 3 /* Abbrev code */ + .uleb128 0x26 /* DW_TAG_const_type */ + .byte 0x0 /* DW_children_no */ + .uleb128 0x49 /* DW_AT_type */ + .uleb128 0x13 /* DW_FORM_ref4 */ + .byte 0x0 /* Terminator */ + .byte 0x0 /* Terminator */ + + .uleb128 4 /* Abbrev code */ + .uleb128 0x34 /* DW_TAG_variable */ + .byte 0x0 /* DW_children_no */ + .uleb128 0x3 /* DW_AT_name */ + .uleb128 0x8 /* DW_FORM_string */ + .uleb128 0x49 /* DW_AT_type */ + .uleb128 0x13 /* DW_FORM_ref4 */ + .uleb128 0x1c /* DW_AT_const_value */ + .uleb128 0xb /* DW_FORM_data1 */ + .byte 0x0 /* Terminator */ + .byte 0x0 /* Terminator */ + .byte 0x0 /* Terminator */ .byte 0x0 /* Terminator */ diff --git a/gdb/testsuite/gdb.dwarf2/dw2-intercu.exp b/gdb/testsuite/gdb.dwarf2/dw2-intercu.exp index 8de99c5..eba791b 100644 --- a/gdb/testsuite/gdb.dwarf2/dw2-intercu.exp +++ b/gdb/testsuite/gdb.dwarf2/dw2-intercu.exp @@ -42,3 +42,8 @@ gdb_test_no_output "set listsize 1" gdb_test "list func_cu1" "4\[ \t\]+File 1 Line 4" gdb_test "ptype func_cu1" "type = int2 \\(\\)" + +gdb_test "p one" "= 1" +gdb_test "p two" "= 2" +gdb_test "ptype one" "type = const int1" +gdb_test "ptype two" "type = const int2"