OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [tags/] [gnu-src/] [gdb-7.2/] [gdb-7.2-or32-1.0rc1/] [gdb/] [testsuite/] [gdb.python/] [py-type.exp] - Blame information for rev 341

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 330 jeremybenn
# Copyright (C) 2009, 2010 Free Software Foundation, Inc.
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 .
15
 
16
# This file is part of the GDB testsuite.  It tests the mechanism
17
# of exposing types to Python.
18
 
19
if $tracelevel then {
20
    strace $tracelevel
21
}
22
 
23
set testfile "py-type"
24
set srcfile ${testfile}.c
25
set binfile ${objdir}/${subdir}/${testfile}
26
 
27
# Build inferior to language specification.
28
proc build_inferior {lang} {
29
  global srcdir subdir srcfile binfile testfile hex
30
 
31
  if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable "debug $lang"] != "" } {
32
      untested "Couldn't compile ${srcfile} in $lang mode"
33
      return -1
34
  }
35
}
36
 
37
# Restart GDB.
38
proc restart_gdb {} {
39
  global srcdir subdir srcfile binfile testfile hex
40
 
41
  gdb_exit
42
  gdb_start
43
  gdb_reinitialize_dir $srcdir/$subdir
44
  gdb_load ${binfile}
45
 
46
  if ![runto_main ] then {
47
      perror "couldn't run to breakpoint"
48
      return
49
  }
50
}
51
 
52
# Set breakpoint and run to that breakpoint.
53
proc runto_bp {bp} {
54
  gdb_breakpoint [gdb_get_line_number $bp]
55
  gdb_continue_to_breakpoint $bp
56
}
57
 
58
# Run a command in GDB, and report a failure if a Python exception is thrown.
59
# If report_pass is true, report a pass if no exception is thrown.
60
proc gdb_py_test_silent_cmd {cmd name report_pass} {
61
  global gdb_prompt
62
 
63
  gdb_test_multiple $cmd $name {
64
      -re "Traceback.*$gdb_prompt $"  { fail $name }
65
      -re "$gdb_prompt $"             { if $report_pass { pass $name } }
66
  }
67
}
68
 
69
proc test_fields {lang} {
70
  global gdb_prompt
71
 
72
  if {$lang == "c++"} {
73
      # Test usage with a class
74
      gdb_py_test_silent_cmd "print c" "print value" 1
75
      gdb_py_test_silent_cmd "python c = gdb.history (0)" "get value from history" 1
76
      gdb_py_test_silent_cmd "python fields = c.type.fields()" "get fields" 1
77
      gdb_test "python print len(fields)" "2" "Check number of fields"
78
      gdb_test "python print fields\[0\].name" "c" "Check class field c name"
79
      gdb_test "python print fields\[1\].name" "d" "Check class field d name"
80
  }
81
 
82
  # Test normal fields usage in structs.
83
  gdb_py_test_silent_cmd "print st" "print value" 1
84
  gdb_py_test_silent_cmd "python st = gdb.history (0)" "get value from history" 1
85
  gdb_py_test_silent_cmd "python fields = st.type.fields()" "get fields" 1
86
  gdb_test "python print len(fields)" "2" "Check number of fields"
87
  gdb_test "python print fields\[0\].name" "a" "Check structure field a name"
88
  gdb_test "python print fields\[1\].name" "b" "Check structure field b name"
89
 
90
  # Test regression PR python/10805
91
  gdb_py_test_silent_cmd "print ar" "print value" 1
92
  gdb_py_test_silent_cmd "python ar = gdb.history (0)" "get value from  history" 1
93
  gdb_test "python fields = ar.type.fields()"
94
  gdb_test "python print len(fields)" "1" "Check the number of fields"
95
  gdb_test "python print fields\[0\].type" "" "Check array field type"
96
}
97
 
98
proc test_base_class {} {
99
  gdb_py_test_silent_cmd "print d" "print value" 1
100
  gdb_py_test_silent_cmd "python d = gdb.history (0)" "get value from  history" 1
101
  gdb_py_test_silent_cmd "python fields = d.type.fields()" "get value from history" 1
102
  gdb_test "python print len(fields)" "3" "Check the number of fields"
103
  gdb_test "python print fields\[0\].is_base_class" "True" "Check base class"
104
  gdb_test "python print fields\[1\].is_base_class" "False" "Check base class"
105
}
106
 
107
proc test_range {} {
108
 
109
  # Test a valid range request.
110
  gdb_py_test_silent_cmd "print ar" "print value" 1
111
  gdb_py_test_silent_cmd "python ar = gdb.history (0)" "get value from history" 1
112
  gdb_test "python print len(ar.type.range())" "2" "Check correct tuple length"
113
  gdb_test "python print ar.type.range()\[0\]" "0" "Check low range"
114
  gdb_test "python print ar.type.range()\[1\]" "1" "Check high range"
115
 
116
  # Test a range request on a ranged type.
117
  gdb_py_test_silent_cmd "print ar" "print value" 1
118
  gdb_py_test_silent_cmd "python ar = gdb.history (0)" "get value from  history" 1
119
  gdb_py_test_silent_cmd "python fields = ar.type.fields()" "get fields" 1
120
  gdb_test "python print fields\[0\].type.range()\[0\]" "0" "Check range type low bound"
121
  gdb_test "python print fields\[0\].type.range()\[1\]" "1" "Check range type high bound"
122
 
123
  # Test where a range does not exist.
124
  gdb_py_test_silent_cmd "print st" "print value" 1
125
  gdb_py_test_silent_cmd "python st = gdb.history (0)" "get value from history" 1
126
  gdb_test "python print st.type.range()" "RuntimeError: This type does not have a range.*" "Check range for non ranged type."
127
}
128
 
129
 
130
# Perform C Tests.
131
build_inferior "c"
132
restart_gdb
133
 
134
# Skip all tests if Python scripting is not enabled.
135
if { [skip_python_tests] } { continue }
136
 
137
runto_bp "break to inspect struct and array."
138
test_fields "c"
139
 
140
# Perform C++ Tests.
141
build_inferior "c++"
142
restart_gdb
143
runto_bp "break to inspect struct and array."
144
test_fields "c++"
145
test_base_class
146
test_range

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.