mirror of
https://github.com/bminor/binutils-gdb.git
synced 2025-12-25 08:47:28 +00:00
New python module gdb.types.
* NEWS: Document it. * data-directory/Makefile.in (PYTHON_FILES): Add gdb/types.py. * python/lib/gdb/types.py: New file. testsuite/ * lib/gdb-python.exp (gdb_check_python_config): New function. * gdb.python/Makefile.in (EXECUTABLES): Add lib-types. * gdb.python/lib-types.cc: New file. * gdb.python/lib-types.exp: New file. doc/ * gdb.texinfo (Python): Add "Python modules". (Types in Python): Add reference to gdb.types section. (Python modules): New node.
This commit is contained in:
@@ -3,7 +3,7 @@ srcdir = @srcdir@
|
||||
|
||||
EXECUTABLES = py-type py-value py-prettyprint py-template py-block \
|
||||
py-symbol py-mi py-breakpoint py-inferior py-infthread \
|
||||
py-shared python
|
||||
py-shared python lib-types
|
||||
|
||||
MISCELLANEOUS = py-shared-sl.sl
|
||||
|
||||
|
||||
61
gdb/testsuite/gdb.python/lib-types.cc
Normal file
61
gdb/testsuite/gdb.python/lib-types.cc
Normal file
@@ -0,0 +1,61 @@
|
||||
/* This testcase is part of GDB, the GNU debugger.
|
||||
|
||||
Copyright 2010 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 class1
|
||||
{
|
||||
public:
|
||||
class1 (int _x) : x (_x) {}
|
||||
int x;
|
||||
};
|
||||
|
||||
class1 class1_obj (42);
|
||||
const class1 const_class1_obj (42);
|
||||
volatile class1 volatile_class1_obj (42);
|
||||
const volatile class1 const_volatile_class1_obj (42);
|
||||
|
||||
typedef class1 typedef_class1;
|
||||
|
||||
typedef_class1 typedef_class1_obj (42);
|
||||
|
||||
class1& class1_ref_obj (class1_obj);
|
||||
|
||||
typedef const typedef_class1 typedef_const_typedef_class1;
|
||||
|
||||
typedef_const_typedef_class1 typedef_const_typedef_class1_obj (42);
|
||||
|
||||
typedef typedef_const_typedef_class1& typedef_const_typedef_class1_ref;
|
||||
|
||||
typedef_const_typedef_class1_ref typedef_const_typedef_class1_ref_obj (typedef_const_typedef_class1_obj);
|
||||
|
||||
class subclass1 : public class1
|
||||
{
|
||||
public:
|
||||
subclass1 (int _x, int _y) : class1 (_x), y (_y) {}
|
||||
int y;
|
||||
};
|
||||
|
||||
subclass1 subclass1_obj (42, 43);
|
||||
|
||||
enum enum1 { A, B, C };
|
||||
|
||||
enum1 enum1_obj (A);
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
143
gdb/testsuite/gdb.python/lib-types.exp
Normal file
143
gdb/testsuite/gdb.python/lib-types.exp
Normal file
@@ -0,0 +1,143 @@
|
||||
# Copyright (C) 2010 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 is part of the GDB testsuite.
|
||||
# It tests the types.py module.
|
||||
|
||||
if $tracelevel then {
|
||||
strace $tracelevel
|
||||
}
|
||||
|
||||
load_lib gdb-python.exp
|
||||
|
||||
set testfile "lib-types"
|
||||
set srcfile ${testfile}.cc
|
||||
set binfile ${objdir}/${subdir}/${testfile}
|
||||
if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
|
||||
untested "Couldn't compile ${srcfile}"
|
||||
return -1
|
||||
}
|
||||
|
||||
# Start with a fresh gdb.
|
||||
gdb_exit
|
||||
gdb_start
|
||||
gdb_reinitialize_dir $srcdir/$subdir
|
||||
gdb_load ${binfile}
|
||||
|
||||
# Skip all tests if Python scripting is not enabled.
|
||||
if { [skip_python_tests] } { continue }
|
||||
|
||||
if ![runto_main] then {
|
||||
fail "Can't run to main"
|
||||
return 0
|
||||
}
|
||||
|
||||
# Ensure sys.path, et.al. are initialized properly.
|
||||
gdb_check_python_config
|
||||
|
||||
gdb_test_no_output "python import gdb.types"
|
||||
|
||||
# test get_basic_type const stripping
|
||||
gdb_test_no_output "python const_class1_obj = gdb.parse_and_eval ('const_class1_obj')"
|
||||
gdb_test_no_output "python basic_type_const_class1_obj = gdb.types.get_basic_type (const_class1_obj.type)"
|
||||
gdb_test "python print str (const_class1_obj.type)" "const class1"
|
||||
set test "const stripping"
|
||||
gdb_test_multiple "python print str (basic_type_const_class1_obj)" $test {
|
||||
-re "\[\r\n\]+class1\[\r\n\]+$gdb_prompt $" {
|
||||
pass $test
|
||||
}
|
||||
}
|
||||
|
||||
# test get_basic_type volatile stripping
|
||||
gdb_test_no_output "python volatile_class1_obj = gdb.parse_and_eval ('volatile_class1_obj')"
|
||||
gdb_test_no_output "python basic_type_volatile_class1_obj = gdb.types.get_basic_type (volatile_class1_obj.type)"
|
||||
gdb_test "python print str (volatile_class1_obj.type)" "volatile class1"
|
||||
set test "volatile stripping"
|
||||
gdb_test_multiple "python print str (basic_type_volatile_class1_obj)" $test {
|
||||
-re "\[\r\n\]+class1\[\r\n\]+$gdb_prompt $" {
|
||||
pass $test
|
||||
}
|
||||
}
|
||||
|
||||
# test get_basic_type volatile+const stripping
|
||||
gdb_test_no_output "python const_volatile_class1_obj = gdb.parse_and_eval ('const_volatile_class1_obj')"
|
||||
gdb_test_no_output "python basic_type_const_volatile_class1_obj = gdb.types.get_basic_type (const_volatile_class1_obj.type)"
|
||||
gdb_test "python print str (const_volatile_class1_obj.type)" "const volatile class1"
|
||||
set test "volatile+const stripping"
|
||||
gdb_test_multiple "python print str (basic_type_const_volatile_class1_obj)" $test {
|
||||
-re "\[\r\n\]+class1\[\r\n\]+$gdb_prompt $" {
|
||||
pass $test
|
||||
}
|
||||
}
|
||||
|
||||
# test get_basic_type typedef stripping
|
||||
gdb_test_no_output "python typedef_class1_obj = gdb.parse_and_eval ('typedef_class1_obj')"
|
||||
gdb_test_no_output "python basic_type_typedef_class1_obj = gdb.types.get_basic_type (typedef_class1_obj.type)"
|
||||
gdb_test "python print str (typedef_class1_obj.type)" "typedef_class1"
|
||||
set test "typedef stripping"
|
||||
gdb_test_multiple "python print str (basic_type_typedef_class1_obj)" $test {
|
||||
-re "\[\r\n\]+class1\[\r\n\]+$gdb_prompt $" {
|
||||
pass $test
|
||||
}
|
||||
}
|
||||
|
||||
# test get_basic_type reference stripping
|
||||
gdb_test_no_output "python class1_ref_obj = gdb.parse_and_eval ('class1_ref_obj')"
|
||||
gdb_test_no_output "python basic_type_class1_ref_obj = gdb.types.get_basic_type (class1_ref_obj.type)"
|
||||
gdb_test "python print str (class1_ref_obj.type)" "class1 &"
|
||||
set test "reference stripping"
|
||||
gdb_test_multiple "python print str (basic_type_class1_ref_obj)" $test {
|
||||
-re "\[\r\n\]+class1\[\r\n\]+$gdb_prompt $" {
|
||||
pass $test
|
||||
}
|
||||
}
|
||||
|
||||
# test nested typedef stripping
|
||||
gdb_test_no_output "python typedef_const_typedef_class1_obj = gdb.parse_and_eval ('typedef_const_typedef_class1_obj')"
|
||||
gdb_test_no_output "python basic_type_typedef_const_typedef_class1_obj = gdb.types.get_basic_type (typedef_const_typedef_class1_obj.type)"
|
||||
gdb_test "python print str (typedef_class1_obj.type)" "typedef_class1"
|
||||
set test "nested typedef stripping"
|
||||
gdb_test_multiple "python print str (basic_type_typedef_const_typedef_class1_obj)" $test {
|
||||
-re "\[\r\n\]+class1\[\r\n\]+$gdb_prompt $" {
|
||||
pass $test
|
||||
}
|
||||
}
|
||||
|
||||
# test nested typedef/reference stripping
|
||||
gdb_test_no_output "python typedef_const_typedef_class1_ref_obj = gdb.parse_and_eval ('typedef_const_typedef_class1_ref_obj')"
|
||||
gdb_test_no_output "python basic_type_typedef_const_typedef_class1_ref_obj = gdb.types.get_basic_type (typedef_const_typedef_class1_ref_obj.type)"
|
||||
gdb_test "python print str (typedef_const_typedef_class1_ref_obj.type)" "const typedef_const_typedef_class1_ref"
|
||||
set test "nested typedef/ref stripping"
|
||||
gdb_test_multiple "python print str (basic_type_typedef_const_typedef_class1_ref_obj)" $test {
|
||||
-re "\[\r\n\]+class1\[\r\n\]+$gdb_prompt $" {
|
||||
pass $test
|
||||
}
|
||||
}
|
||||
|
||||
# test has_field on simple class
|
||||
gdb_test_no_output "python class1_obj = gdb.parse_and_eval ('class1_obj')"
|
||||
gdb_test "python print gdb.types.has_field (class1_obj.type, 'x')" "True"
|
||||
gdb_test "python print gdb.types.has_field (class1_obj.type, 'nope')" "False"
|
||||
|
||||
# test has_field in base class
|
||||
gdb_test_no_output "python subclass1_obj = gdb.parse_and_eval ('subclass1_obj')"
|
||||
gdb_test "python print gdb.types.has_field (subclass1_obj.type, 'x')" "True"
|
||||
|
||||
# test make_enum_dict
|
||||
gdb_test_no_output "python enum1_obj = gdb.parse_and_eval ('enum1_obj')"
|
||||
gdb_test_no_output "python enum1_dict = gdb.types.make_enum_dict (enum1_obj.type)"
|
||||
gdb_test_no_output "python enum1_list = enum1_dict.items ()"
|
||||
gdb_test_no_output "python enum1_list.sort ()"
|
||||
gdb_test "python print enum1_list" {\[\('A', 0L\), \('B', 1L\), \('C', 2L\)\]}
|
||||
Reference in New Issue
Block a user