Fix: Null pointer dereference in ldlex.l
[binutils-gdb.git] / gdb / testsuite / gdb.base / print-internal-string.exp
blobbe5b2f38206a470758cac2f3bbdc2028ffb00055
1 # Copyright 2023 Free Software Foundation, Inc.
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.
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.
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/>.
16 # Test different ways in which GDB can create a string and then push
17 # that string into the inferior before reading it back. Check that
18 # the thing that is read back is correctly interpreted as a string.
20 standard_testfile
22 if { [prepare_for_testing "failed to prepare" $testfile $srcfile] } {
23 return -1
26 if {![runto_main]} {
27 return 0
30 if [allow_python_tests] {
31 # The $_as_string convenience function is implemented in Python.
32 gdb_test {printf "%s\n", $_as_string("aabbcc")} "\"aabbcc\""
34 # Create a gdb.Value object for a string. Take its address (which
35 # forces it into the inferior), and then print the address as a
36 # string.
37 gdb_test_no_output {python addr = gdb.Value("ccbbaa").address}
38 gdb_test {python gdb.execute("x/1s 0x%x" % addr)} \
39 "$hex <arena>:\\s+\"ccbbaa\""
41 # Call an inferior function through a gdb.Value object, pass a
42 # string to the inferior function and ensure it arrives correctly.
43 gdb_test "p/x take_string" " = $hex.*"
44 gdb_test_no_output "python func_ptr = gdb.history (0)" \
45 "place address of take_string into Python variable"
46 gdb_test "python func_value = func_ptr.dereference()" ""
47 gdb_breakpoint "take_string"
48 gdb_test {python result = func_value("qqaazz")} \
49 "Breakpoint $decimal, take_string \\(str=$hex <arena> \"qqaazz\"\\) at .*"
50 gdb_test "continue" "Continuing\\."
53 # Use printf on a string parsed by the C expression parser.
54 gdb_test {printf "%s\n", "ddeeff"} "ddeeff"
56 # Parse a string in the C expression parser, force it into the
57 # inferior by taking its address, then print it as a string.
58 gdb_test {x/1s &"gghhii"} "$hex <arena>:\\s+\"gghhii\""
60 # Use $_gdb_setting_str and $_gdb_maint_setting_str to create a string
61 # value, and then print using printf, which forces the string into the
62 # inferior.
63 gdb_test {printf "%s\n", $_gdb_setting_str("arch")} "auto"
64 gdb_test {printf "%s\n", $_gdb_maint_setting_str("bfd-sharing")} "on"