mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2025-03-13 13:49:00 +08:00
Trying to print a packed array sometimes leads to a crash (see attached testcase for an example of when this happens): | (gdb) p bad | [1] 65571 segmentation fault gdb -q foo Variable "bad" is declared in the debug information as an array where the array's type name has an XPnnn suffix: | .uleb128 0xc # (DIE (0x566) DW_TAG_typedef) | .long .LASF200 # DW_AT_name: "pck__t___XP1" | [loc info attributes snipped] | .long 0x550 # DW_AT_type | .byte 0x1 # DW_AT_alignment The signals to GDB that the debugging information follows a GNAT encoding used for packed arrays, and an in order to decode it, we need to find the type whose name is the same minus the "___XPnnn" suffix: "pck__t". For that, we make a call to ada-lang.c::standard_lookup, which is a simple function which essentially does: | /* Return the result of a standard (literal, C-like) lookup of NAME in | given DOMAIN, visible from lexical block BLOCK. */ | | [...] | sym = lookup_symbol_in_language (name, block, domain, language_c, 0); Unfortunately for us, while the intent of this call was to perform an exact-match lookup, in our case, it returns ... type pck__t___XP1 instead! In other words, it finds itself back. The reason why it finds this type is a confluence of two factors: (1) Forcing the lookup into language_c currently does not affect how symbol matching is done anymore, because we look at the symbol's language to determine which kind of matching should be done; (2) The lookup searches the local context (via block) first, beforei doing a more general lookup. And looking at the debug info for the main subprogram, we see that type "pck__t" is not declared there, only in the debug info for pck.ads. In other words, there is no way that we accidently find "pck__t" by random chance. I believe Pedro added a new function called ada_lookup_encoded_symbol for that specific purpose, so I started by replacing the lookup by language above by this. Unfortunately, still no joy. This was because, even though ada_lookup_encoded_symbol puts angle- brackets around the search name to signal that we want a verbatim search, we end up losing that information in the function called to compare a symbol with the search name: | static bool | do_full_match (const char *symbol_search_name, | const lookup_name_info &lookup_name, | completion_match_result *comp_match_res) | { | return full_match (symbol_search_name, ada_lookup_name (lookup_name)); ^^^^^^^^^^^^^^^ | <=> lookup_name.m_ada.m_encoded_name (no angle brackets) The way I fixed this was by introducing a new function called do_exact_match, and then adjust ada_get_symbol_name_matcher to return that function when seeing that we have a verbatim non-wild-match search. As it happens, this fixes an incorrect test in gdb.ada/homony.exp, where we were inserting a breakpoint on a symbol using the angle-brackets notation, and got 2 locations for that breakpoint... (gdb) b <homonym__get_value> Breakpoint 1 at 0x4029fc: <homonym__get_value>. (2 locations) ... each location being in a different function: (gdb) info break Num Type Disp Enb Address What 1 breakpoint keep y <MULTIPLE> 1.1 y 0x00000000004029fc in homonym.get_value at /[...]/homonym.adb:32 1.2 y 0x0000000000402a3a in homonym.get_value at /[...]/homonym.adb:50 (gdb) x /i 0x00000000004029fc 0x4029fc <homonym__get_value+8>: movl $0x1d,-0x4(%rbp) (gdb) x /i 0x0000000000402a3a 0x402a3a <homonym__get_value__2+8>: movl $0x11,-0x4(%rbp) Since we used angle-brackets, we shouldn't be matching the second one, something this patch fixes. gdb/ChangeLog: * ada-lang.c (standard_lookup): Use ada_lookup_encoded_symbol instead of lookup_symbol_in_language (do_exact_match): New function. (ada_get_symbol_name_matcher): Return do_exact_match when doing a verbatim match. gdb/testsuite/ChangeLog: * gdb.ada/big_packed_array: New testcase. * gdb.ada/homonym.exp: Fix incorrect expected output for "break <homonym__get_value>" test. Tested on x86_64-linux.
99 lines
3.1 KiB
Plaintext
99 lines
3.1 KiB
Plaintext
# Copyright 2008-2019 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/>.
|
|
|
|
load_lib "ada.exp"
|
|
|
|
standard_ada_testfile homonym_main
|
|
|
|
if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug]] != "" } {
|
|
return -1
|
|
}
|
|
|
|
clean_restart ${testfile}
|
|
|
|
|
|
# Do these tests before running, so we are operating in a known
|
|
# environment.
|
|
|
|
gdb_test "break Get_Value" \
|
|
"Breakpoint \[0-9\]+ at $hex: Get_Value. .2 locations." \
|
|
"set breakpoint at Get_Value"
|
|
|
|
gdb_test "break homonym.adb:Get_Value" \
|
|
"Breakpoint \[0-9\]+ at $hex: homonym.adb:Get_Value. .2 locations." \
|
|
"set breakpoint at homonym.adb:Get_Value"
|
|
|
|
gdb_test "break <homonym__get_value>" \
|
|
"Breakpoint \[0-9\]+ at $hex: file .*homonym\\.adb, line $decimal\\." \
|
|
"set breakpoint at <homonym__get_value>"
|
|
|
|
delete_breakpoints
|
|
|
|
set bp_location [gdb_get_line_number "BREAK_1" ${testdir}/homonym.adb]
|
|
runto "homonym.adb:$bp_location"
|
|
|
|
# Check the variables and types defined inside the current scope.
|
|
# There are some homonyms in a different scope, so we want to make
|
|
# sure that the debugger doesn't get mixed up.
|
|
|
|
gdb_test "ptype local_type" \
|
|
"type = range -100 \\.\\. 100" \
|
|
"ptype local_type at BREAK_1"
|
|
|
|
gdb_test "ptype local_type_subtype" \
|
|
"type = range -100 \\.\\. 100" \
|
|
"ptype local_type_subtype at BREAK_1"
|
|
|
|
gdb_test "ptype int_type" \
|
|
"type = range -100 \\.\\. 100" \
|
|
"ptype int_type at BREAK_1"
|
|
|
|
gdb_test "ptype lcl" \
|
|
"type = range -100 \\.\\. 100" \
|
|
"ptype lcl at BREAK_1"
|
|
|
|
gdb_test "print lcl" \
|
|
"= 29" \
|
|
"print lcl at BREAK_1"
|
|
|
|
# Now, continue until reaching BREAK_2, and do the same commands
|
|
# as above. The result should be different since the definitions
|
|
# in the new scope are different.
|
|
|
|
set bp_location [gdb_get_line_number "BREAK_2" ${testdir}/homonym.adb]
|
|
gdb_test "break homonym.adb:$bp_location" \
|
|
"Breakpoint \[0-9\]+ at 0x\[0-9a-fA-F\]+: file .*homonym\.adb, line \[0-9\]+\." \
|
|
"break at BREAK_2"
|
|
|
|
gdb_test "continue" \
|
|
".*Breakpoint \[0-9\]+, homonym\\.get_value \\(\\) at .*homonym\\.adb:.*" \
|
|
"continue until BREAK_2"
|
|
|
|
gdb_test "ptype local_type" \
|
|
"type = range 1 \\.\\. 19740804" \
|
|
"ptype local_type at BREAK_2"
|
|
|
|
gdb_test "ptype local_type_subtype" \
|
|
"type = range 1 \\.\\. 19740804" \
|
|
"ptype local_type_subtype at BREAK_2"
|
|
|
|
gdb_test "ptype lcl" \
|
|
"type = range 1 \\.\\. 19740804" \
|
|
"ptype lcl at BREAK_2"
|
|
|
|
gdb_test "print lcl" \
|
|
"= 17" \
|
|
"print lcl at BREAK_2"
|