mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2025-01-24 12:35:55 +08:00
a8e9d24718
Currently each language has a la_print_typedef method, this is only used for the "info types" command. The documentation for "info types" says: Print a brief description of all types whose names match the regular expression @var{regexp} (or all types in your program, if you supply no argument). However, if we consider this C code: typedef struct { int a; } my_type; Then currently with "info types" this will be printed like this: 3: typedef struct { int a; } my_type; I see two problems with this, first the indentation is clearly broken, second, if the struct contained more fields then it feels like the actual type names could easily get lost in the noise. Given that "info types" is about discovering type names, I think there is an argument to be made that we should focus on giving _only_ the briefest summary for "info types", and if the user wants to know more they can take the type name and plug it into "ptype". As such, I propose that a better output would be: 3: typedef struct {...} my_type; The user understands that there is a type called `my_type`, and that it's an alias for an anonymous structure type. The change to achieve this turns out to be pretty simple, but only effects languages that make use of c_print_typedef, which are C, C++, asm, minimal, d, go, objc, and opencl. Other languages will for now do whatever they used to do. The patch to change how anonymous structs are displayed also changes the display of anonymous enums, consider this code sample: typedef enum { AA, BB, CC } anon_enum_t; This used to be displayed like this: 3: typedef enum {AA, BB, CC} anon_enum_t; Which will quickly become cluttered for enums with a large number of values. The modified output looks like this: 3: typedef enum {...} anon_enum_t; Again, the user can always make use of ptype if they want to see the details of the anon_enum_t type. It is worth pointing out that this change (to use {...}) only effects anonymous structs and enums, named types don't change with this patch, consider this code: struct struct_t { int i; }; enum enum_t { AA, BB, CC }; The output from 'info types' remains unchanged, like this: 4: enum enum_t; 1: struct struct_t; An additional area of interest is how C++ handles anonymous types used within a typedef; enums are handled basically inline with how C handles them, but structs (and classes) are slightly different. The behaviour before the patch is different, and is unchanged by this patch. Consider this code compiled for C++: typedef struct { int i; } struct_t; Both before and after this patch, this is show by 'info types' as: 3: typedef struct_t struct_t; Unions are displayed similarly to structs in both C and C++, the handling of anonymous unions changes for C in the same way that it changes for anonymous structs. I did look at ada, as this is the only language to actually have some tests for "info types", however, as I understand it ada doesn't really support typedefs, however, by forcing the language we can see what ada would print. So, if we 'set language ada', then originally we printed this: 3: record a: int; end record Again the indentation is clearly broken, but we also have no mention of the type name at all, which is odd, but understandable given the lack of typedefs. If I make a similar change as I'm proposing for C, then we now get this output: 3: record ... end record Which is even less informative I think. However, the original output _is_ tested for in gdb.ada/info_auto_lang.exp, and its not clear to me if the change is a good one or not, so for now I have left this out. gdb/ChangeLog: * c-typeprint.c (c_print_typedef): Pass -1 instead of 0 to type_print. gdb/testsuite/ChangeLog: * gdb.ada/info_auto_lang.exp: Update expected results. * gdb.base/info-types.c: Add additional types to check. * gdb.base/info-types.exp: Update expected results.
156 lines
5.2 KiB
Plaintext
156 lines
5.2 KiB
Plaintext
# Copyright 2018-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"
|
|
|
|
# This test verifies that the commands
|
|
# info [functions|variables|types]
|
|
# respect the 'set language auto|ada|c' setting, whatever the language
|
|
# of the current frame.
|
|
# Similarly, checks that rbreak reports its results respecting
|
|
# the language mode.
|
|
|
|
standard_ada_testfile proc_in_ada
|
|
set cfile "some_c"
|
|
# gnat normalizes proc_in_ada source file when compiling.
|
|
# As the 'info' commands results are sorted by absolute path names, also normalize
|
|
# the some_c source file to ensure that the 'info' results are always
|
|
# giving Ada results first.
|
|
set csrcfile [file normalize ${srcdir}/${subdir}/${testdir}/${cfile}.c]
|
|
set cobject [standard_output_file ${cfile}.o]
|
|
|
|
if { [gdb_compile "${csrcfile}" "${cobject}" object [list debug]] != "" } {
|
|
untested "failed to compile"
|
|
return -1
|
|
}
|
|
if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug]] != "" } {
|
|
untested "failed to compile"
|
|
return -1
|
|
}
|
|
|
|
clean_restart ${testfile}
|
|
|
|
set bp_location [gdb_get_line_number "STOP" ${testdir}/some_c.c]
|
|
if ![runto "some_c.c:$bp_location"] then {
|
|
fail "can't run to some_c.c STOP location"
|
|
return
|
|
}
|
|
|
|
set func_in_c(c_syntax) "${decimal}: void proc_in_c\\\(void\\\);"
|
|
set func_in_c(ada_syntax) "${decimal}: procedure proc_in_c;"
|
|
set func_in_ada(c_syntax) "${decimal}: void proc_in_ada\\\(void\\\);"
|
|
set func_in_ada(ada_syntax) "${decimal}: procedure proc_in_ada;"
|
|
|
|
set type_in_c(c_syntax) "${decimal}: typedef struct {\\.\\.\\.} some_type_in_c;"
|
|
set type_in_c(ada_syntax) [multi_line \
|
|
"${decimal}: record" \
|
|
" some_component_in_c: int;" \
|
|
"end record" ]
|
|
set type_in_ada(c_syntax) "${decimal}: struct global_pack__some_type_in_ada;"
|
|
set type_in_ada(ada_syntax) "${decimal}: global_pack.some_type_in_ada;"
|
|
|
|
set var_in_c(c_syntax) "${decimal}: some_type_in_c some_struct_in_c;"
|
|
set var_in_c(ada_syntax) "${decimal}: some_struct_in_c: some_type_in_c;"
|
|
set var_in_ada(c_syntax) "${decimal}: struct global_pack__some_type_in_ada global_pack.some_struct_in_ada;"
|
|
set var_in_ada(ada_syntax) "${decimal}: global_pack.some_struct_in_ada: global_pack.some_type_in_ada;"
|
|
|
|
set rbreak_func_in_c(c_syntax) "void proc_in_c\\\(void\\\);"
|
|
set rbreak_func_in_c(ada_syntax) "procedure proc_in_c;"
|
|
set rbreak_func_in_ada(c_syntax) "void proc_in_ada\\\(void\\\);"
|
|
set rbreak_func_in_ada(ada_syntax) "procedure proc_in_ada;"
|
|
|
|
|
|
foreach_with_prefix language_choice { "auto" "ada" "c" } {
|
|
|
|
# Check that switching to the desired language_choice when the selected
|
|
# frame has the same language (or the desired language is auto) gives no
|
|
# warning. Also set the expected matches for the various commands
|
|
# tested afterwards.
|
|
if {$language_choice == "auto"} {
|
|
gdb_test "frame 0" "#0 .*" "select frame with lang c"
|
|
set c_match c_syntax
|
|
set ada_match ada_syntax
|
|
} elseif {$language_choice == "ada"} {
|
|
gdb_test "frame 1" "#1 .*" "select frame with lang ada"
|
|
set c_match ada_syntax
|
|
set ada_match ada_syntax
|
|
} elseif {$language_choice == "c"} {
|
|
gdb_test "frame 0" "#0 .*" "select frame with lang c"
|
|
set c_match c_syntax
|
|
set ada_match c_syntax
|
|
} else {
|
|
error "unexpected language choice"
|
|
}
|
|
gdb_test_no_output "set language $language_choice" "set language language_choice"
|
|
|
|
foreach frame {
|
|
"0"
|
|
"1" } {
|
|
if { $frame == 0 } {
|
|
set frame_lang "c"
|
|
} else {
|
|
set frame_lang "ada"
|
|
}
|
|
|
|
with_test_prefix "frame=$frame, frame_lang=$frame_lang" {
|
|
|
|
gdb_test "frame $frame" "#$frame .*" "select frame"
|
|
|
|
gdb_test "info functions proc_in_" \
|
|
[multi_line \
|
|
"All functions matching regular expression \"proc_in_\":" \
|
|
"" \
|
|
"File .*proc_in_ada.adb:" \
|
|
$func_in_ada($ada_match) \
|
|
"" \
|
|
"File .*some_c.c:" \
|
|
$func_in_c($c_match)
|
|
]
|
|
|
|
gdb_test "info types some_type" \
|
|
[multi_line \
|
|
"All types matching regular expression \"some_type\":" \
|
|
"" \
|
|
"File .*global_pack.ads:" \
|
|
$type_in_ada($ada_match)\
|
|
"" \
|
|
"File .*some_c.c:" \
|
|
$type_in_c($c_match)
|
|
]
|
|
|
|
gdb_test "info variables some_struct" \
|
|
[multi_line \
|
|
"All variables matching regular expression \"some_struct\":" \
|
|
"" \
|
|
"File .*global_pack.ads:" \
|
|
$var_in_ada($ada_match) \
|
|
"" \
|
|
"File .*some_c.c:" \
|
|
$var_in_c($c_match)
|
|
]
|
|
|
|
gdb_test "rbreak proc_in_" \
|
|
[multi_line \
|
|
"Breakpoint.*file .*proc_in_ada.adb,.*" \
|
|
$rbreak_func_in_ada($ada_match) \
|
|
"Breakpoint.*file .*some_c.c,.*" \
|
|
$rbreak_func_in_c($c_match)
|
|
]
|
|
delete_breakpoints
|
|
}
|
|
}
|
|
}
|
|
|