diff options
Diffstat (limited to 'gdb/testsuite')
-rw-r--r-- | gdb/testsuite/gdb.python/py-pp-cast.c | 35 | ||||
-rw-r--r-- | gdb/testsuite/gdb.python/py-pp-cast.exp | 40 | ||||
-rw-r--r-- | gdb/testsuite/gdb.python/py-pp-cast.py | 28 |
3 files changed, 103 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.python/py-pp-cast.c b/gdb/testsuite/gdb.python/py-pp-cast.c new file mode 100644 index 0000000..72716a7 --- /dev/null +++ b/gdb/testsuite/gdb.python/py-pp-cast.c @@ -0,0 +1,35 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2023 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/>. */ + +typedef int pp_int; + +int break_function() +{ + return 0; +} + +struct container +{ + pp_int p_i; + int i; +}; + +int main() +{ + struct container c = { 10, 5 }; + return break_function(); +} diff --git a/gdb/testsuite/gdb.python/py-pp-cast.exp b/gdb/testsuite/gdb.python/py-pp-cast.exp new file mode 100644 index 0000000..8a6f297 --- /dev/null +++ b/gdb/testsuite/gdb.python/py-pp-cast.exp @@ -0,0 +1,40 @@ +# Copyright (C) 2023 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 casting of a gdb.Value inside a pretty printer. + +load_lib gdb-python.exp + +require allow_python_tests + +standard_testfile + +if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } { + return -1 +} + +if ![runto break_function] { + return -1 +} + +set remote_python_file [gdb_remote_download host \ + ${srcdir}/${subdir}/${testfile}.py] + +gdb_test_no_output "source ${remote_python_file}" \ + "source ${testfile}.py" + +gdb_test "up" "#1.*main.*" + +gdb_test "info locals" "c = {p_i = 10p, i = 5}" diff --git a/gdb/testsuite/gdb.python/py-pp-cast.py b/gdb/testsuite/gdb.python/py-pp-cast.py new file mode 100644 index 0000000..b171a91 --- /dev/null +++ b/gdb/testsuite/gdb.python/py-pp-cast.py @@ -0,0 +1,28 @@ +# Copyright (C) 2023 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/>. + + +class PpIntPrinter(object): + def __init__(self, val): + self.val = val + + def to_string(self): + val = self.val.cast(self.val.type) + return "%dp" % int(val) + + +pp = gdb.printing.RegexpCollectionPrettyPrinter("pp-cast") +pp.add_printer("pp_int", "^pp_int$", PpIntPrinter) +gdb.printing.register_pretty_printer(gdb.current_objfile(), pp) |