]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/print-internal-string.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / print-internal-string.exp
CommitLineData
1d506c26 1# Copyright 2023-2024 Free Software Foundation, Inc.
baab3753
AB
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# 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.
19
20standard_testfile
21
22if { [prepare_for_testing "failed to prepare" $testfile $srcfile] } {
23 return -1
24}
25
26if {![runto_main]} {
27 return 0
28}
29
30if [allow_python_tests] {
31 # The $_as_string convenience function is implemented in Python.
32 gdb_test {printf "%s\n", $_as_string("aabbcc")} "\"aabbcc\""
33
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\""
40
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\\."
51}
52
53# Use printf on a string parsed by the C expression parser.
54gdb_test {printf "%s\n", "ddeeff"} "ddeeff"
55
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.
58gdb_test {x/1s &"gghhii"} "$hex <arena>:\\s+\"gghhii\""
59
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.
63gdb_test {printf "%s\n", $_gdb_setting_str("arch")} "auto"
64gdb_test {printf "%s\n", $_gdb_maint_setting_str("bfd-sharing")} "on"