diff mbox

[v2,D] Don't recursively look for a symbol in all imports of imported modules.

Message ID CABOHX+euRdxFcOF-JG3YtjEdzPD3A_7EAb4RD7V-gNFntZVh1A@mail.gmail.com
State New
Headers show

Commit Message

Iain Buclaw Jan. 30, 2016, 1:31 p.m. UTC
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.
diff mbox

Patch

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 <http://www.gnu.org/licenses/>.  */
+
+/* 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 <http://www.gnu.org/licenses/>.
+
+# 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."