a280dbd160
<https://sourceware.org/ml/gdb-patches/2013-09/msg00301.html> <https://sourceware.org/ml/gdb-patches/2013-09/msg00383.html> This patch adds a new convenience function called $_isvoid, whose only purpose is to check whether an expression is void or not. This became necessary because the new convenience variable $_exitsignal (not yet approved) has a mutual exclusive behavior with $_exitcode, i.e., when one is "defined" (i.e., non-void), the other is cleared (i.e., becomes void). Doug wanted a way to identify which variable to use, and checking for voidness is the obvious solution. It is worth mentioning that my first attempt, after a conversation with Doug, was to actually implement a new $_isdefined() convenience function. I would do that (for convenience variables) by calling lookup_only_internalvar. However, I found a few problems: - Whenever I called $_isdefined ($variable), $variable became defined (with a void value), and $_isdefined always returned true. - Then, I tried to implement $_isdefined ("variable"), and do the "$" + "variable" inside GDB, thus making it impossible for GDB to create the convenience variable. However, it was hard to extract the string without having to mess with values and their idiossincrasies. Therefore, I decided to abandon this attempt (specially because I didn't want to spend too much time struggling with it). Anyway, after talking to Doug again we decided that it would be easier to implement $_isvoid, and this will probably help in cases like <http://stackoverflow.com/questions/3744554/testing-if-a-gdb-convenience-variable-is-defined>. I wrote a NEWS entry for it, and some new lines on the documentation. gdb/ 2013-09-16 Sergio Durigan Junior <sergiodj@redhat.com> * NEWS: Mention new convenience function $_isvoid. * value.c (isvoid_internal_fn): New function. (_initialize_values): Add new convenience function $_isvoid. gdb/doc/ 2013-09-16 Sergio Durigan Junior <sergiodj@redhat.com> * gdb.texinfo (Convenience Functions): Mention new convenience function $_isvoid. gdb/testsuite/ 2013-09-16 Sergio Durigan Junior <sergiodj@redhat.com> * gdb.base/gdbvars.c (foo_void): New function. (foo_int): Likewise. * gdb.base/gdbvars.exp (test_convenience_functions): New function. Call it.
146 lines
4.3 KiB
Text
146 lines
4.3 KiB
Text
# Copyright (C) 1992-2013 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 written by Fred Fish. (fnf@cygnus.com)
|
|
|
|
|
|
standard_testfile
|
|
|
|
if {[prepare_for_testing $testfile.exp $testfile $srcfile debug]} {
|
|
untested $testfile.exp
|
|
return -1
|
|
}
|
|
|
|
proc test_convenience_variables {} {
|
|
global gdb_prompt
|
|
|
|
gdb_test_no_output "set \$foo = 101" \
|
|
"Set a new convenience variable"
|
|
|
|
gdb_test "print \$foo" " = 101" \
|
|
"Print contents of new convenience variable"
|
|
|
|
gdb_test_no_output "set \$foo = 301" \
|
|
"Set convenience variable to a new value"
|
|
|
|
gdb_test "print \$foo" " = 301" \
|
|
"Print new contents of convenience variable"
|
|
|
|
gdb_test_no_output "set \$_ = 11" \
|
|
"Set convenience variable \$_"
|
|
|
|
gdb_test "print \$_" " = 11" \
|
|
"Print contents of convenience variable \$_"
|
|
|
|
gdb_test "print \$foo + 10" " = 311" \
|
|
"Use convenience variable in arithmetic expression"
|
|
|
|
gdb_test "print (\$foo = 32) + 4" " = 36" \
|
|
"Use convenience variable assignment in arithmetic expression"
|
|
|
|
gdb_test "print \$bar" " = void" \
|
|
"Print contents of uninitialized convenience variable"
|
|
}
|
|
|
|
proc test_convenience_functions {} {
|
|
gdb_test "print \$_isvoid" " = <internal function _isvoid>" \
|
|
"Print internal function \$_isvoid"
|
|
|
|
gdb_test "print \$isvoid_foo" " = void" \
|
|
"Print void convenience variable"
|
|
|
|
gdb_test "print \$_isvoid (\$isvoid_foo)" " = 1" \
|
|
"Check whether void convenience variable is void"
|
|
|
|
gdb_test_no_output "set \$isvoid_foo = 1" \
|
|
"Set void convenience variable to 1"
|
|
|
|
gdb_test "print \$_isvoid (\$isvoid_foo)" " = 0" \
|
|
"Check whether non-void convenience variable is void"
|
|
|
|
# For the next test, we need the inferior to be running.
|
|
if { ![runto_main] } {
|
|
return -1
|
|
}
|
|
|
|
gdb_test "print \$_isvoid (foo_void ())" " = 1" \
|
|
"Check whether void function is void"
|
|
|
|
gdb_test "print \$_isvoid (foo_int ())" " = 0" \
|
|
"Check whether non-void function is void"
|
|
}
|
|
|
|
proc test_value_history {} {
|
|
global gdb_prompt
|
|
|
|
gdb_test "print 101" "\\\$1 = 101" \
|
|
"Set value-history\[1\] using \$1"
|
|
|
|
gdb_test "print 102" "\\\$2 = 102" \
|
|
"Set value-history\[2\] using \$2"
|
|
|
|
gdb_test "print 103" "\\\$3 = 103" \
|
|
"Set value-history\[3\] using \$3"
|
|
|
|
gdb_test "print \$\$" "\\\$4 = 102" \
|
|
"Print value-history\[MAX-1\] using inplicit index \$\$"
|
|
|
|
gdb_test "print \$\$" "\\\$5 = 103" \
|
|
"Print value-history\[MAX-1\] again using implicit index \$\$"
|
|
|
|
gdb_test "print \$" "\\\$6 = 103" \
|
|
"Print value-history\[MAX\] using implicit index \$"
|
|
|
|
gdb_test "print \$\$2" "\\\$7 = 102" \
|
|
"Print value-history\[MAX-2\] using explicit index \$\$2"
|
|
|
|
gdb_test "print \$0" "\\\$8 = 102" \
|
|
"Print value-history\[MAX\] using explicit index \$0"
|
|
|
|
gdb_test "print 108" "\\\$9 = 108"
|
|
|
|
gdb_test "print \$\$0" "\\\$10 = 108" \
|
|
"Print value-history\[MAX\] using explicit index \$\$0"
|
|
|
|
gdb_test "print \$1" "\\\$11 = 101" \
|
|
"Print value-history\[1\] using explicit index \$1"
|
|
|
|
gdb_test "print \$2" "\\\$12 = 102" \
|
|
"Print value-history\[2\] using explicit index \$2"
|
|
|
|
gdb_test "print \$3" "\\\$13 = 103" \
|
|
"Print value-history\[3\] using explicit index \$3"
|
|
|
|
gdb_test "print \$-3" "\\\$14 = 100" \
|
|
"Print (value-history\[MAX\] - 3) using implicit index \$"
|
|
|
|
gdb_test "print \$1 + 3" "\\\$15 = 104" \
|
|
"Use value-history element in arithmetic expression"
|
|
}
|
|
|
|
proc test_with_program {} {
|
|
global hex
|
|
gdb_test_no_output "set \$prog_var = p" \
|
|
"Set a new convenience variable to a program variable"
|
|
gdb_test "print /x \$prog_var" " = $hex" \
|
|
"Print contents of new convenience variable of program variable"
|
|
}
|
|
|
|
gdb_test_no_output "set print sevenbit-strings"
|
|
|
|
test_value_history
|
|
test_convenience_variables
|
|
test_convenience_functions
|
|
test_with_program
|