From patchwork Sat Jan 30 13:31:13 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Buclaw X-Patchwork-Id: 10672 Received: (qmail 33133 invoked by alias); 30 Jan 2016 13:31:21 -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 33110 invoked by uid 89); 30 Jan 2016 13:31:19 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.6 required=5.0 tests=AWL, BAYES_40, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=dw_at_producer, DW_AT_producer, Length, Offset X-HELO: mail-wm0-f66.google.com Received: from mail-wm0-f66.google.com (HELO mail-wm0-f66.google.com) (74.125.82.66) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Sat, 30 Jan 2016 13:31:16 +0000 Received: by mail-wm0-f66.google.com with SMTP id r129so2012410wmr.0 for ; Sat, 30 Jan 2016 05:31:15 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:date:message-id:subject:from :to:content-type; bh=eLeF7UKn8BlrS9Pfjnl/IfmzNH9Nxuc1c+Aj8+xyR6Y=; b=HlBUJUIp1MzTs17VWjHFdNtffPvxwIy26l+TD+nGv4ko2du5M2bhGeR8aa0aAJYVic qvxFesaCfXLGog5smKm4sFX3vamF99hVT5AM4XXzonalys523EqjlggqGL+iBuxpDYOl YXW3Sw4iApl4zswaIjTWeaxtMPAUf3nm1FtTZPR+PnqmTWFt/2XzRDXXeLkLQp8GA5Tl bmcgJBMBAdVbf+bkrQ7GcAz7P4rIjiU+my/+pQ+axI58g/U9rkcMzV+L9myoqbhenWzD nJKYpXIFLwFUFTrErt/n34liSxhf9LUv4Q1qTa+t+HB9X/rnrObfydDvEdjnwLlpCwof Zv5A== X-Gm-Message-State: AG10YORlNzvIfwA6FLi7OiLukUuBn+bgsnKJMnSJ2+cIOvd2nZsKLsHsbo7J1jCBkPgNpQ5U6WY2v1uAbX1VCQ== MIME-Version: 1.0 X-Received: by 10.28.46.87 with SMTP id u84mr2877178wmu.102.1454160673401; Sat, 30 Jan 2016 05:31:13 -0800 (PST) Received: by 10.28.211.1 with HTTP; Sat, 30 Jan 2016 05:31:13 -0800 (PST) Date: Sat, 30 Jan 2016 14:31:13 +0100 Message-ID: Subject: [PATCH v2] [D] Don't recursively look for a symbol in all imports of imported modules. From: Iain Buclaw To: GDB Patches , Pedro Alves , Doug Evans X-IsSubscribed: yes I know it's a few months later, but I managed to get a nice reduced test case that triggers (near-)infinite looping bug when looking up symbols in D with 5 modules, all importing each other. Test file is in x86_64 assembly produced by GDC. Iain. gdb/ChangeLog: * d-namespace.c (d_lookup_symbol_imports): Remove argument 'search_parents'. All callers updated. gdb/testsuite/ChangeLog: * gdb.dlang/circular.S: New file. * gdb.dlang/circular.exp: New file. --- diff --git a/gdb/d-namespace.c b/gdb/d-namespace.c index bcd0f45..fbf1ca7 100644 --- a/gdb/d-namespace.c +++ b/gdb/d-namespace.c @@ -508,9 +508,9 @@ d_lookup_symbol_imports (const char *scope, const char *name, { /* Skip the '.' */ name_scope++; - sym = d_lookup_symbol_imports (current->import_src, - name + name_scope, - block, domain, 0); + sym = d_lookup_symbol_in_module (current->import_src, + name + name_scope, + block, domain, 1); } } } @@ -519,8 +519,8 @@ d_lookup_symbol_imports (const char *scope, const char *name, /* If this import statement creates no alias, pass current->import_src as MODULE to direct the search towards the imported module. */ - sym = d_lookup_symbol_imports (current->import_src, - name, block, domain, 0); + sym = d_lookup_symbol_in_module (current->import_src, + name, block, domain, 1); } current->searched = 0; discard_cleanups (searched_cleanup); diff --git a/gdb/testsuite/gdb.dlang/circular.S b/gdb/testsuite/gdb.dlang/circular.S new file mode 100644 index 0000000..f87633b --- /dev/null +++ b/gdb/testsuite/gdb.dlang/circular.S @@ -0,0 +1,336 @@ +/* Copyright 2016 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 . */ + +/* This file was generated using: + + $ gdc -g circular{1,2,3,4,5}.d -S -o circular.S + + with + + $ gdc -v + gcc version 6.0.0 20160123 (experimental) (GCC) + Target: x86_64-pc-linux-gnu + Thread model: posix + + And then manually edited with debug comments. */ + .file "circular1.d" + .text +.Ltext0: + .globl _D9circular15foundFZv + .type _D9circular15foundFZv, @function +_D9circular15foundFZv: # @_D9circular15foundFZv +.LFB0: + .file 1 "circular1.d" + .loc 1 7 0 # circular1.d:7:0 + .cfi_startproc + pushq %rbp + .cfi_def_cfa_offset 16 + .cfi_offset 6, -16 + movq %rsp, %rbp + .cfi_def_cfa_register 6 + .loc 1 7 0 # circular1.d:7:0 + nop + .loc 1 9 0 # circular1.d:9:0 + popq %rbp + .cfi_def_cfa 7, 8 + ret + .cfi_endproc +.LFE0: + .size _D9circular15foundFZv, .-_D9circular15foundFZv + .globl main + .type main, @function +main: # @main +.LFB1: + .loc 1 11 0 # circular1.d:11:0 + .cfi_startproc + pushq %rbp + .cfi_def_cfa_offset 16 + .cfi_offset 6, -16 + movq %rsp, %rbp + .cfi_def_cfa_register 6 + .loc 1 13 0 # circular1.d:13:0 + call _D9circular15foundFZv + .loc 1 14 0 # circular1.d:14:0 + nop + popq %rbp + .cfi_def_cfa 7, 8 + ret + .cfi_endproc +.LFE1: + .size main, .-main +.Letext0: + .file 2 "circular2.d" + .file 3 "circular3.d" + .file 4 "circular4.d" + .file 5 "circular5.d" + .section .debug_info,"",@progbits +.Ldebug_info0: + .long 0x11e # Length of Compilation Unit Info + .value 0x4 # DWARF version number + .long .Ldebug_abbrev0 # Offset Into Abbrev. Section + .byte 0x8 # Size of Address + .uleb128 0x1 # DW_TAG_compile_unit (Abbrev[1]) + .long .Linfo_string0 # DW_AT_producer + .byte 0x13 # DW_AT_language (D) + .long .Linfo_string1 # DW_AT_name + .long .Linfo_string2 # DW_AT_comp_dir + .quad .Ltext0 # DW_AT_low_pc + .quad .Letext0-.Ltext0 # DW_AT_high_pc + .long .Ldebug_line0 # DW_AT_stmt_list + .uleb128 0x2 # DW_TAG_module (Abbrev[2]) + .long .Linfo_string3 # DW_AT_name + .long 0x70 # DW_AT_sibling + .uleb128 0x3 # DW_TAG_imported_module (Abbrev[3]) + .byte 0x1 # DW_AT_decl_file + .byte 0x2 # DW_AT_decl_line + .long 0x70 # DW_AT_import + .uleb128 0x3 # DW_TAG_imported_module (Abbrev[3]) + .byte 0x1 # DW_AT_decl_file + .byte 0x3 # DW_AT_decl_line + .long 0x96 # DW_AT_import + .uleb128 0x3 # DW_TAG_imported_module (Abbrev[3]) + .byte 0x1 # DW_AT_decl_file + .byte 0x4 # DW_AT_decl_line + .long 0xbc # DW_AT_import + .uleb128 0x3 # DW_TAG_imported_module (Abbrev[3]) + .byte 0x1 # DW_AT_decl_line + .byte 0x5 # DW_AT_decl_line + .long 0xe2 # DW_AT_import + .uleb128 0x4 # DW_TAG_subprogram (Abbrev[4]) + .long .Linfo_string4 # DW_AT_name + .byte 0x1 # DW_AT_decl_file + .byte 0x7 # DW_AT_decl_line + .long .Linfo_string5 # DW_AT_linkage_name + .quad .LFB0 # DW_AT_low_pc + .quad .LFE0-.LFB0 # DW_AT_high_pc + .uleb128 0x1 # DW_AT_frame_base + .byte 0x9c # DW_OP_call_frame_cfa + .byte 0 + .uleb128 0x2 # DW_TAG_module (Abbrev[2]) + .long .Linfo_string6 # DW_AT_name + .long 0x96 # DW_AT_sibling + .uleb128 0x3 # DW_TAG_imported_module (Abbrev[3]) + .byte 0x2 # DW_AT_decl_file + .byte 0x2 # DW_AT_decl_line + .long 0x2d # DW_AT_import + .uleb128 0x3 # DW_TAG_imported_module (Abbrev[3]) + .byte 0x2 # DW_AT_decl_file + .byte 0x3 # DW_AT_decl_line + .long 0x96 # DW_AT_import + .uleb128 0x3 # DW_TAG_imported_module (Abbrev[3]) + .byte 0x2 # DW_AT_decl_file + .byte 0x4 # DW_AT_decl_line + .long 0xbc # DW_AT_import + .uleb128 0x3 # DW_TAG_imported_module (Abbrev[3]) + .byte 0x2 # DW_AT_decl_file + .byte 0x5 # DW_AT_decl_line + .long 0xe2 # DW_AT_import + .byte 0 + .uleb128 0x2 # DW_TAG_module (Abbrev[2]) + .long .Linfo_string7 # DW_AT_name + .long 0xbc # DW_AT_sibling + .uleb128 0x3 # DW_TAG_imported_module (Abbrev[3]) + .byte 0x3 # DW_AT_decl_file + .byte 0x2 # DW_AT_decl_line + .long 0x2d # DW_AT_import + .uleb128 0x3 # DW_TAG_imported_module (Abbrev[3]) + .byte 0x3 # DW_AT_decl_file + .byte 0x3 # DW_AT_decl_line + .long 0x70 # DW_AT_import + .uleb128 0x3 # DW_TAG_imported_module (Abbrev[3]) + .byte 0x3 # DW_AT_decl_file + .byte 0x4 # DW_AT_decl_line + .long 0xbc # DW_AT_import + .uleb128 0x3 # DW_TAG_imported_module (Abbrev[3]) + .byte 0x3 # DW_AT_decl_file + .byte 0x5 # DW_AT_decl_line + .long 0xe2 # DW_AT_import + .byte 0 + .uleb128 0x2 # DW_TAG_module (Abbrev[2]) + .long .Linfo_string8 # DW_AT_name + .long 0xe2 # DW_AT_sibling + .uleb128 0x3 # DW_TAG_imported_module (Abbrev[3]) + .byte 0x4 # DW_AT_decl_file + .byte 0x2 # DW_AT_decl_line + .long 0x2d # DW_AT_import + .uleb128 0x3 # DW_TAG_imported_module (Abbrev[3]) + .byte 0x4 # DW_AT_decl_file + .byte 0x3 # DW_AT_decl_line + .long 0x70 # DW_AT_import + .uleb128 0x3 # DW_TAG_imported_module (Abbrev[3]) + .byte 0x4 # DW_AT_decl_file + .byte 0x4 # DW_AT_decl_line + .long 0x96 # DW_AT_import + .uleb128 0x3 # DW_TAG_imported_module (Abbrev[3]) + .byte 0x4 # DW_AT_decl_file + .byte 0x5 # DW_AT_decl_line + .long 0xe2 # DW_AT_import + .byte 0 + .uleb128 0x2 # DW_TAG_module (Abbrev[2]) + .long .Linfo_string9 # DW_AT_name + .long 0x108 # DW_AT_sibling + .uleb128 0x3 # DW_TAG_imported_module (Abbrev[3]) + .byte 0x5 # DW_AT_decl_file + .byte 0x2 # DW_AT_decl_line + .long 0x2d # DW_AT_import + .uleb128 0x3 # DW_TAG_imported_module (Abbrev[3]) + .byte 0x5 # DW_AT_decl_file + .byte 0x3 # DW_AT_decl_line + .long 0x70 # DW_AT_import + .uleb128 0x3 # DW_TAG_imported_module (Abbrev[3]) + .byte 0x5 # DW_AT_decl_file + .byte 0x4 # DW_AT_decl_line + .long 0x96 # DW_AT_import + .uleb128 0x3 # DW_TAG_imported_module (Abbrev[3]) + .byte 0x5 # DW_AT_decl_file + .byte 0x5 # DW_AT_decl_line + .long 0xbc # DW_AT_import + .byte 0 + .uleb128 0x5 # DW_TAG_subprogram (Abbrev[5]) + .long .Linfo_string10 # DW_AT_name + .byte 0x1 # DW_AT_decl_file + .byte 0xb # DW_AT_decl_line + .quad .LFB1 # DW_AT_low_pc + .quad .LFE1-.LFB1 # DW_AT_high_pc + .uleb128 0x1 # DW_AT_frame_base + .byte 0x9c # DW_OP_call_frame_cfa + .byte 0 + .section .debug_abbrev,"",@progbits +.Ldebug_abbrev0: + .uleb128 0x1 # Abbrev: 1 + .uleb128 0x11 # DW_TAG_compile_unit + .byte 0x1 # DW_children_yes + .uleb128 0x25 # DW_AT_producer + .uleb128 0xe # DW_FORM_strp + .uleb128 0x13 # DW_AT_language + .uleb128 0xb # DW_FORM_data1 + .uleb128 0x3 # DW_AT_name + .uleb128 0xe # DW_FORM_strp + .uleb128 0x1b # DW_AT_comp_dir + .uleb128 0xe # DW_FORM_strp + .uleb128 0x11 # DW_AT_low_pc + .uleb128 0x1 # DW_FORM_addr + .uleb128 0x12 # DW_AT_high_pc + .uleb128 0x7 # DW_FORM_data8 + .uleb128 0x10 # DW_AT_stmt_list + .uleb128 0x17 # DW_FORM_sec_offset + .byte 0 + .byte 0 + .uleb128 0x2 # Abbrev: 2 + .uleb128 0x1e # DW_TAG_module + .byte 0x1 # DW_children_yes + .uleb128 0x3 # DW_AT_name + .uleb128 0xe # DW_FORM_strp + .uleb128 0x3c # DW_AT_declaration + .uleb128 0x19 # DW_FORM_flag_present + .uleb128 0x1 # DW_AT_sibling + .uleb128 0x13 # DW_FORM_ref4 + .byte 0 + .byte 0 + .uleb128 0x3 # Abbrev: 3 + .uleb128 0x3a # DW_TAG_imported_module + .byte 0 # DW_children_no + .uleb128 0x3a # DW_AT_decl_file + .uleb128 0xb # DW_FORM_data1 + .uleb128 0x3b # DW_AT_decl_line + .uleb128 0xb # DW_FORM_data1 + .uleb128 0x18 # DW_AT_import + .uleb128 0x13 # DW_FORM_ref4 + .byte 0 + .byte 0 + .uleb128 0x4 # Abbrev: 4 + .uleb128 0x2e # DW_TAG_subprogram + .byte 0 # DW_children_no + .uleb128 0x3f # DW_AT_external + .uleb128 0x19 # DW_FORM_flag_present + .uleb128 0x3 # DW_AT_name + .uleb128 0xe # DW_FORM_strp + .uleb128 0x3a # DW_AT_decl_file + .uleb128 0xb # DW_FORM_data1 + .uleb128 0x3b # DW_AT_decl_line + .uleb128 0xb # DW_FORM_data1 + .uleb128 0x6e # DW_AT_linkage_name + .uleb128 0xe # DW_FORM_strp + .uleb128 0x11 # DW_AT_low_pc + .uleb128 0x1 # DW_FORM_addr + .uleb128 0x12 # DW_AT_high_pc + .uleb128 0x7 # DW_FORM_data8 + .uleb128 0x40 # DW_AT_frame_base + .uleb128 0x18 # DW_FORM_exprloc + .uleb128 0x2117 # DW_AT_GNU_all_call_sites + .uleb128 0x19 # DW_FORM_flag_present + .byte 0 + .byte 0 + .uleb128 0x5 # Abbrev: 5 + .uleb128 0x2e # DW_TAG_subprogram + .byte 0 # DW_children_no + .uleb128 0x3f # DW_AT_external + .uleb128 0x19 # DW_FORM_flag_present + .uleb128 0x3 # DW_AT_name + .uleb128 0xe # DW_FORM_strp + .uleb128 0x3a # DW_AT_decl_file + .uleb128 0xb # DW_FORM_data1 + .uleb128 0x3b # DW_AT_decl_line + .uleb128 0xb # DW_FORM_data1 + .uleb128 0x11 # DW_AT_low_pc + .uleb128 0x1 # DW_FORM_addr + .uleb128 0x12 # DW_AT_high_pc + .uleb128 0x7 # DW_FORM_data8 + .uleb128 0x40 # DW_AT_frame_base + .uleb128 0x18 # DW_FORM_exprloc + .uleb128 0x2116 # DW_AT_GNU_all_tail_call_sites + .uleb128 0x19 # DW_FORM_flag_present + .byte 0 + .byte 0 + .byte 0 + .section .debug_aranges,"",@progbits + .long 0x2c # Length of Address Ranges Info + .value 0x2 # DWARF Version + .long .Ldebug_info0 # Offset of Compilation Unit Info + .byte 0x8 # Size of Address + .byte 0 # Size of Segment Descriptor + .value 0 # Pad to 16 byte boundary + .value 0 + .quad .Ltext0 # Address + .quad .Letext0-.Ltext0 # Length + .quad 0 + .quad 0 + .section .debug_line,"",@progbits +.Ldebug_line0: + .section .debug_str,"MS",@progbits,1 +.Linfo_string0: + .string "GNU D 6.0.0 20160123 (experimental)" +.Linfo_string1: + .string "circular1.d" +.Linfo_string2: + .string "/tmp" +.Linfo_string3: + .string "circular1" +.Linfo_string4: + .string "found" +.Linfo_string5: + .string "_D9circular15foundFZv" +.Linfo_string6: + .string "circular2" +.Linfo_string7: + .string "circular3" +.Linfo_string8: + .string "circular4" +.Linfo_string9: + .string "circular5" +.Linfo_string10: + .string "main" + .ident "GCC: (GNU) 6.0.0 20160123 (experimental)" + .section .note.GNU-stack,"",@progbits diff --git a/gdb/testsuite/gdb.dlang/circular.exp b/gdb/testsuite/gdb.dlang/circular.exp new file mode 100644 index 0000000..b12ad9b --- /dev/null +++ b/gdb/testsuite/gdb.dlang/circular.exp @@ -0,0 +1,43 @@ +# Copyright (C) 2016 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 . + +# Test symbol lookup when there are multiple circular imports. + +load_lib "d-support.exp" +load_lib "dwarf.exp" + +if { [skip_d_tests] } { continue } + +# This test can only be run on x86-like targets which support DWARF. +if {![dwarf2_support] || ![istarget "x86_64-*-*"] || ![is_lp64_target]} { + return 0 +} + +standard_testfile .S + +# Compile and start with a fresh gdb. + +if {[prepare_for_testing $testfile.exp $testfile $srcfile {nodebug}]} { + return -1 +} + +if {![runto_main]} { + return -1 +} + +# Step into our D function, and try a couple search queries. +gdb_test "step" "" +gdb_test "print found" ".*circular1.found\(\).*" +gdb_test "print notfound" "No symbol \"notfound\" in current context."