diff options
author | Andrew Burgess <andrew.burgess@embecosm.com> | 2019-09-24 23:35:47 +0100 |
---|---|---|
committer | Andrew Burgess <andrew.burgess@embecosm.com> | 2019-11-27 12:01:55 +0000 |
commit | 7dc42066097ca6188ecd2c505d865e68d84998ee (patch) | |
tree | a91d0455a292e5ba87a480b7b4498c2a8b44a0bc /gdb/testsuite | |
parent | 5f512a7dd0df1205630e9edfaa84f2e9a8fb8771 (diff) | |
download | binutils-gdb-7dc42066097ca6188ecd2c505d865e68d84998ee.tar.gz |
gdb/mi: Add new commands -symbol-info-{functions,variables,types}
Add new MI commands -symbol-info-functions, -symbol-info-variables,
and -symbol-info-types which correspond to the CLI commands 'info
functions', 'info variables', and 'info types' respectively.
gdb/ChangeLog:
* mi/mi-cmds.c (mi_cmds): Add '-symbol-info-functions',
'-symbol-info-types', and '-symbol-info-variables'.
* mi/mi-cmds.h (mi_cmd_symbol_info_functions): Declare.
(mi_cmd_symbol_info_types): Declare.
(mi_cmd_symbol_info_variables): Declare.
* mi/mi-symbol-cmds.c: Add 'source.h' and 'mi-getopt.h' includes.
(output_debug_symbol): New function.
(output_nondebug_symbol): New function.
(mi_symbol_info): New function.
(mi_info_functions_or_variables): New function.
(mi_cmd_symbol_info_functions): New function.
(mi_cmd_symbol_info_types): New function.
(mi_cmd_symbol_info_variables): New function.
* NEWS: Mention new commands.
gdb/testsuite/ChangeLog:
* gdb.mi/mi-sym-info-1.c: New file.
* gdb.mi/mi-sym-info-2.c: New file.
* gdb.mi/mi-sym-info.exp: New file.
gdb/doc/ChangeLog:
* doc/gdb.texinfo (GDB/MI Symbol Query): Document new MI command
-symbol-info-functions, -symbol-info-types, and
-symbol-info-variables.
Change-Id: Ic2fc6a6750bbce91cdde2344791014e5ef45642d
Diffstat (limited to 'gdb/testsuite')
-rw-r--r-- | gdb/testsuite/ChangeLog | 6 | ||||
-rw-r--r-- | gdb/testsuite/gdb.mi/mi-sym-info-1.c | 48 | ||||
-rw-r--r-- | gdb/testsuite/gdb.mi/mi-sym-info-2.c | 43 | ||||
-rw-r--r-- | gdb/testsuite/gdb.mi/mi-sym-info.exp | 129 |
4 files changed, 226 insertions, 0 deletions
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 9073bc7ad55..f8ce265eed8 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2019-11-27 Andrew Burgess <andrew.burgess@embecosm.com> + + * gdb.mi/mi-sym-info-1.c: New file. + * gdb.mi/mi-sym-info-2.c: New file. + * gdb.mi/mi-sym-info.exp: New file. + 2019-11-22 Tom Tromey <tromey@adacore.com> * gdb.ada/tasks.exp: Add -ada-task-info regression test. diff --git a/gdb/testsuite/gdb.mi/mi-sym-info-1.c b/gdb/testsuite/gdb.mi/mi-sym-info-1.c new file mode 100644 index 00000000000..9b6dc7396ad --- /dev/null +++ b/gdb/testsuite/gdb.mi/mi-sym-info-1.c @@ -0,0 +1,48 @@ +/* Copyright 2019 Free Software Foundation, Inc. + + This file is part of GDB. + + 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/>. */ + +/* Function and variables declared in mi-sym-info-2.c. */ +extern float f2 (float arg); +extern int f3 (int arg); +extern int global_i2; +extern float global_f2; + +static int global_i1; +static float global_f1; + +typedef int my_int_t; + +static my_int_t +f1 (int arg1, int arg2) +{ + return arg1 + arg2; +} + +void +f4 (int *arg) +{ + (*arg)++; +} + +int +main () +{ + int v = f3 (4); + f4 (&v); + float tmp = f2 (1.0); + return f1 (3, v) + ((int) tmp); +} diff --git a/gdb/testsuite/gdb.mi/mi-sym-info-2.c b/gdb/testsuite/gdb.mi/mi-sym-info-2.c new file mode 100644 index 00000000000..c80877d8e7b --- /dev/null +++ b/gdb/testsuite/gdb.mi/mi-sym-info-2.c @@ -0,0 +1,43 @@ +/* Copyright 2019 Free Software Foundation, Inc. + + This file is part of GDB. + + 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/>. */ + +static int global_i1; +static float global_f1; +int global_i2; +int global_f2; + +typedef int another_int_t; +typedef float another_float_t; + +static another_float_t +f1 (int arg) +{ + return (float) arg; +} + +float +f2 (another_float_t arg) +{ + return arg + f1 (1); +} + +int +f3 (another_int_t arg) +{ + return arg + 2; +} + diff --git a/gdb/testsuite/gdb.mi/mi-sym-info.exp b/gdb/testsuite/gdb.mi/mi-sym-info.exp new file mode 100644 index 00000000000..33fe8657811 --- /dev/null +++ b/gdb/testsuite/gdb.mi/mi-sym-info.exp @@ -0,0 +1,129 @@ +# Copyright 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/>. + +# Test -symbol-info-functions, -symbol-info-variables, and +# -symbol-info-types. + +load_lib mi-support.exp +set MIFLAGS "-i=mi" + +standard_testfile mi-sym-info-1.c mi-sym-info-2.c + +if {[prepare_for_testing "failed to prepare" ${testfile} \ + [list $srcfile $srcfile2] {debug}]} { + return -1 +} + +gdb_exit +if {[mi_gdb_start]} { + continue +} + +mi_run_to_main + +set qstr "\"\[^\"\]+\"" +set fun_re "\{line=\"$decimal\",name=${qstr},type=${qstr},description=${qstr}\}" +set type_re "\{(?:line=\"$decimal\",)*name=${qstr}\}" +set sym_list "\\\[${fun_re}(?:,$fun_re)*\\\]" +set type_sym_list "\\\[${type_re}(?:,$type_re)*\\\]" +set symtab_re \ + "\{filename=${qstr},fullname=${qstr},symbols=${sym_list}\}" +set symtab_type_re \ + "\{filename=${qstr},fullname=${qstr},symbols=${type_sym_list}\}" +set debug_only_syms \ + "symbols=\{debug=\\\[${symtab_re}(?:,${symtab_re})*\\\]\}" +set all_syms \ + "symbols=\{debug=\\\[${symtab_re}(?:,${symtab_re})*\\\],nondebug=\\\[.*\\\]\}" +set type_syms \ + "symbols=\{debug=\\\[${symtab_type_re}(?:,${symtab_type_re})*\\\]\}" + +# Fetch all functions, variables and types without any non-debug +# symbols. +mi_gdb_test "111-symbol-info-functions" \ + "111\\^done,${debug_only_syms}" \ + "List all functions from debug information only" + +mi_gdb_test "112-symbol-info-variables" \ + "112\\^done,${debug_only_syms}" \ + "List all variables from debug information only" + +mi_gdb_test "113-symbol-info-types" \ + "113\\^done,${type_syms}" \ + "List all types" + +# Fetch functions and variables but also grab the non-debug symbols +# (from the symbol table). There's often so much output output from +# this command that we overflow expect's buffers, avoid this by +# fetching the output piece by piece. +set testname "List all functions" +gdb_test_multiple "114-symbol-info-functions --include-nondebug" ${testname} { + -re "114\\^done,symbols=\{debug=\\\[${symtab_re}(?:,${symtab_re})*\\\],nondebug=\\\[" { + exp_continue + } + + -re "\{address=${qstr},name=${qstr}\}," { + exp_continue + } + + -re "\{address=${qstr},name=${qstr}\}\\\]\}\r\n${mi_gdb_prompt}$" { + pass ${testname} + } +} + +set testname "List all variables" +gdb_test_multiple "115-symbol-info-variables --include-nondebug" ${testname} { + -re "115\\^done,symbols=\{debug=\\\[${symtab_re}(?:,${symtab_re})*\\\],nondebug=\\\[" { + verbose -log "Got the first part of the input" + exp_continue + } + + -re "\{address=${qstr},name=${qstr}\}," { + exp_continue + } + + -re "\{address=${qstr},name=${qstr}\}\\\]\}\r\n${mi_gdb_prompt}$" { + pass ${testname} + } +} + +# Filter functions by name and type. +set lineno [gdb_get_line_number "f3 (another_int_t arg)" ${srcfile2}] +mi_gdb_test "116-symbol-info-functions --name f3" \ + "116\\^done,symbols=\{debug=\\\[\{filename=\"\[^\"\]+$srcfile2\",fullname=\"\[^\"\]+$srcfile2\",symbols=\\\[\{line=\"39\",name=\"f3\",type=\"int \\(another_int_t\\)\",description=\"int f3\\(another_int_t\\);\"\}\\\]\}\\\]\}" \ + "List all functions matching pattern f3" + +set lineno [gdb_get_line_number "f4 (int *arg)" ${srcfile}] +mi_gdb_test "117-symbol-info-functions --type void" \ + "117\\^done,symbols=\{debug=\\\[\{filename=\"\[^\"\]+$srcfile\",fullname=\"\[^\"\]+$srcfile\",symbols=\\\[\{line=\"36\",name=\"f4\",type=\"void \\(int \\*\\)\",description=\"void f4\\(int \\*\\);\"\}\\\]\}\\\]\}" \ + "List all functions matching type void" + +# Filter variables by name and type. +set lineno [gdb_get_line_number "int global_f2;" ${srcfile2}] +mi_gdb_test "118-symbol-info-variables --name global_f2" \ + "118\\^done,symbols=\{debug=\\\[\{filename=\"\[^\"\]+$srcfile2\",fullname=\"\[^\"\]+$srcfile2\",symbols=\\\[\{line=\"21\",name=\"global_f2\",type=\"int\",description=\"int global_f2;\"\}\\\]\}\\\]\}" \ + "List all variables matching pattern global_f2" + +set lineno1 [gdb_get_line_number "static float global_f1;" ${srcfile}] +set lineno2 [gdb_get_line_number "static float global_f1;" ${srcfile2}] +mi_gdb_test "119-symbol-info-variables --type float" \ + "119\\^done,symbols=\{debug=\\\[\{filename=\"\[^\"\]+$srcfile\",fullname=\"\[^\"\]+$srcfile\",symbols=\\\[\{line=\"25\",name=\"global_f1\",type=\"float\",description=\"static float global_f1;\"\}\\\]\},\{filename=\"\[^\"\]+$srcfile2\",fullname=\"\[^\"\]+$srcfile2\",symbols=\\\[\{line=\"19\",name=\"global_f1\",type=\"float\",description=\"static float global_f1;\"\}\\\]\}\\\]\}" \ + "List all variables matching type float" + +# Fetch types, filtering by name. +set lineno1 [gdb_get_line_number "typedef int my_int_t;" ${srcfile}] +set lineno2 [gdb_get_line_number "typedef int another_int_t;" ${srcfile2}] +mi_gdb_test "120-symbol-info-types --name _int_" \ + "120\\^done,symbols=\{debug=\\\[\{filename=\"\[^\"\]+$srcfile\",fullname=\"\[^\"\]+$srcfile\",symbols=\\\[\{line=\"27\",name=\"my_int_t\"\}\\\]\},\{filename=\"\[^\"\]+$srcfile2\",fullname=\"\[^\"\]+$srcfile2\",symbols=\\\[\{line=\"23\",name=\"another_int_t\"\}\\\]\}\\\]\}" \ + "List all types matching _int_" |