Skip to content

Commit a2cd4f1

Browse files
committed
(Ada) fix GDB crash printing packed array
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.
1 parent aa9e1dc commit a2cd4f1

File tree

8 files changed

+161
-2
lines changed

8 files changed

+161
-2
lines changed

gdb/ChangeLog

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
2019-02-17 Joel Brobecker <brobecker@adacore.com>
2+
3+
* ada-lang.c (standard_lookup): Use ada_lookup_encoded_symbol
4+
instead of lookup_symbol_in_language
5+
(do_exact_match): New function.
6+
(ada_get_symbol_name_matcher): Return do_exact_match when
7+
doing a verbatim match.
8+
19
2019-02-15 Tom Tromey <tromey@adacore.com>
210

311
* ravenscar-thread.c (ravenscar_thread_target::resume)

gdb/ada-lang.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4760,7 +4760,7 @@ standard_lookup (const char *name, const struct block *block,
47604760

47614761
if (lookup_cached_symbol (name, domain, &sym.symbol, NULL))
47624762
return sym.symbol;
4763-
sym = lookup_symbol_in_language (name, block, domain, language_c, 0);
4763+
ada_lookup_encoded_symbol (name, block, domain, &sym);
47644764
cache_symbol (name, domain, sym.symbol, sym.block);
47654765
return sym.symbol;
47664766
}
@@ -14175,6 +14175,16 @@ do_full_match (const char *symbol_search_name,
1417514175
return full_match (symbol_search_name, ada_lookup_name (lookup_name));
1417614176
}
1417714177

14178+
/* symbol_name_matcher_ftype for exact (verbatim) matches. */
14179+
14180+
static bool
14181+
do_exact_match (const char *symbol_search_name,
14182+
const lookup_name_info &lookup_name,
14183+
completion_match_result *comp_match_res)
14184+
{
14185+
return strcmp (symbol_search_name, ada_lookup_name (lookup_name)) == 0;
14186+
}
14187+
1417814188
/* Build the Ada lookup name for LOOKUP_NAME. */
1417914189

1418014190
ada_lookup_name_info::ada_lookup_name_info (const lookup_name_info &lookup_name)
@@ -14285,6 +14295,8 @@ ada_get_symbol_name_matcher (const lookup_name_info &lookup_name)
1428514295
{
1428614296
if (lookup_name.ada ().wild_match_p ())
1428714297
return do_wild_match;
14298+
else if (lookup_name.ada ().verbatim_p ())
14299+
return do_exact_match;
1428814300
else
1428914301
return do_full_match;
1429014302
}

gdb/testsuite/ChangeLog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
2019-02-17 Joel Brobecker <brobecker@adacore.com>
2+
3+
* gdb.ada/big_packed_array: New testcase.
4+
* gdb.ada/homonym.exp: Fix incorrect expected output for
5+
"break <homonym__get_value>" test.
6+
17
2019-02-13 Weimin Pan <weimin.pan@oracle.com>
28

39
PR breakpoints/21870
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Copyright 2019 Free Software Foundation, Inc.
2+
#
3+
# This program is free software; you can redistribute it and/or modify
4+
# it under the terms of the GNU General Public License as published by
5+
# the Free Software Foundation; either version 3 of the License, or
6+
# (at your option) any later version.
7+
#
8+
# This program is distributed in the hope that it will be useful,
9+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
# GNU General Public License for more details.
12+
#
13+
# You should have received a copy of the GNU General Public License
14+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
15+
16+
load_lib "ada.exp"
17+
18+
if { [skip_ada_tests] } { return -1 }
19+
20+
standard_ada_testfile foo_ra24_010
21+
22+
if {[gdb_compile_ada "${srcfile}" "${binfile}" executable {debug}] != ""} {
23+
return -1
24+
}
25+
26+
clean_restart ${testfile}
27+
28+
set bp_location [gdb_get_line_number "STOP" ${testdir}/foo_ra24_010.adb]
29+
runto "foo_ra24_010.adb:$bp_location"
30+
31+
gdb_test "print good" \
32+
"= \\(false <repeats 196 times>\\)" \
33+
34+
gdb_test "print bad" \
35+
"= \\(false <repeats 196 times>\\)" \
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
-- Copyright 2019 Free Software Foundation, Inc.
2+
--
3+
-- This program is free software; you can redistribute it and/or modify
4+
-- it under the terms of the GNU General Public License as published by
5+
-- the Free Software Foundation; either version 3 of the License, or
6+
-- (at your option) any later version.
7+
--
8+
-- This program is distributed in the hope that it will be useful,
9+
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
-- GNU General Public License for more details.
12+
--
13+
-- You should have received a copy of the GNU General Public License
14+
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
15+
16+
with Pck; use Pck;
17+
18+
procedure Foo_RA24_010 is
19+
Good : PA := (others => False);
20+
Bad : Bad_Packed_Table := (others => False);
21+
begin
22+
Do_Nothing (Good'Address); -- STOP
23+
Do_Nothing (Bad'Address);
24+
end Foo_RA24_010;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
-- Copyright 2019 Free Software Foundation, Inc.
2+
--
3+
-- This program is free software; you can redistribute it and/or modify
4+
-- it under the terms of the GNU General Public License as published by
5+
-- the Free Software Foundation; either version 3 of the License, or
6+
-- (at your option) any later version.
7+
--
8+
-- This program is distributed in the hope that it will be useful,
9+
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
-- GNU General Public License for more details.
12+
--
13+
-- You should have received a copy of the GNU General Public License
14+
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
15+
16+
package body Pck is
17+
procedure Do_Nothing (A : System.Address) is
18+
begin
19+
null;
20+
end Do_Nothing;
21+
end Pck;
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
-- Copyright 2019 Free Software Foundation, Inc.
2+
--
3+
-- This program is free software; you can redistribute it and/or modify
4+
-- it under the terms of the GNU General Public License as published by
5+
-- the Free Software Foundation; either version 3 of the License, or
6+
-- (at your option) any later version.
7+
--
8+
-- This program is distributed in the hope that it will be useful,
9+
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
-- GNU General Public License for more details.
12+
--
13+
-- You should have received a copy of the GNU General Public License
14+
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
15+
16+
with System;
17+
18+
package Pck is
19+
type Enum_Idx is
20+
(e_000, e_001, e_002, e_003, e_004, e_005, e_006, e_007, e_008,
21+
e_009, e_010, e_011, e_012, e_013, e_014, e_015, e_016, e_017,
22+
e_018, e_019, e_020, e_021, e_022, e_023, e_024, e_025, e_026,
23+
e_027, e_028, e_029, e_030, e_031, e_032, e_033, e_034, e_035,
24+
e_036, e_037, e_038, e_039, e_040, e_041, e_042, e_043, e_044,
25+
e_045, e_046, e_047, e_048, e_049, e_050, e_051, e_052, e_053,
26+
e_054, e_055, e_056, e_057, e_058, e_059, e_060, e_061, e_062,
27+
e_063, e_064, e_065, e_066, e_067, e_068, e_069, e_070, e_071,
28+
e_072, e_073, e_074, e_075, e_076, e_077, e_078, e_079, e_080,
29+
e_081, e_082, e_083, e_084, e_085, e_086, e_087, e_088, e_089,
30+
e_090, e_091, e_092, e_093, e_094, e_095, e_096, e_097, e_098,
31+
e_099, e_100, e_101, e_102, e_103, e_104, e_105, e_106, e_107,
32+
e_108, e_109, e_110, e_111, e_112, e_113, e_114, e_115, e_116,
33+
e_117, e_118, e_119, e_120, e_121, e_122, e_123, e_124, e_125,
34+
e_126, e_127, e_128, e_129, e_130, e_131, e_132, e_133, e_134,
35+
e_135, e_136, e_137, e_138, e_139, e_140, e_141, e_142, e_143,
36+
e_144, e_145, e_146, e_147, e_148, e_149, e_150, e_151, e_152,
37+
e_153, e_154, e_155, e_156, e_157, e_158, e_159, e_160, e_161,
38+
e_162, e_163, e_164, e_165, e_166, e_167, e_168, e_169, e_170,
39+
e_171, e_172, e_173, e_174, e_175, e_176, e_177, e_178, e_179,
40+
e_180, e_181, e_182, e_183, e_184, e_185, e_186, e_187, e_188,
41+
e_189, e_190, e_191, e_192, e_193, e_194, e_195);
42+
43+
type PA is array (Enum_Idx) of Boolean;
44+
pragma Pack (PA);
45+
46+
type T is array (Enum_Idx) of Boolean;
47+
pragma Pack (T);
48+
T_Empty : constant T := (others => False);
49+
50+
type Bad_Packed_Table is new T;
51+
52+
Procedure Do_Nothing (A : System.Address);
53+
end Pck;

gdb/testsuite/gdb.ada/homonym.exp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ gdb_test "break homonym.adb:Get_Value" \
3636
"set breakpoint at homonym.adb:Get_Value"
3737

3838
gdb_test "break <homonym__get_value>" \
39-
"Breakpoint \[0-9\]+ at $hex: <homonym__get_value>. .2 locations." \
39+
"Breakpoint \[0-9\]+ at $hex: file .*homonym\\.adb, line $decimal\\." \
4040
"set breakpoint at <homonym__get_value>"
4141

4242
delete_breakpoints

0 commit comments

Comments
 (0)