OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gdb/] [gdb-6.8/] [gdb/] [testsuite/] [gdb.mi/] [gdb669.exp] - Blame information for rev 25

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 25 jlechner
# Copyright 2002, 2003, 2004, 2007, 2008 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
# Please email any bugs, comments, and/or additions to this file to:
17
# bug-gdb@prep.ai.mit.edu
18
 
19
# This file checks for the bug gdb/669, where the console
20
# command "info threads" and the MI command "-thread-list-ids"
21
# return different threads in the system.
22
 
23
# This only works with native configurations
24
if {![isnative]} {
25
  return
26
}
27
 
28
load_lib mi-support.exp
29
set MIFLAGS "-i=mi"
30
 
31
gdb_exit
32
if {[mi_gdb_start]} {
33
    continue
34
}
35
 
36
# The procs below are all stolen from mi-pthreads.exp. Any updates
37
# should also be made to the procs there.
38
 
39
proc get_mi_thread_list {name} {
40
  global expect_out
41
 
42
  # MI will return a list of thread ids:
43
  #
44
  # -thread-list-ids
45
  # ^done,thread-ids=[thread-id="1",thread-id="2",...],number-of-threads="N"
46
  # (gdb)
47
  mi_gdb_test "-thread-list-ids" \
48
    {\^done,thread-ids={(thread-id="[0-9]+"(,)?)+},number-of-threads="[0-9]+"} \
49
    "-thread_list_ids ($name)"
50
 
51
  set output {}
52
  if {[info exists expect_out(buffer)]} {
53
    set output $expect_out(buffer)
54
  }
55
  set thread_list {}
56
  if {![regexp {thread-ids=\{(thread-id="[0-9]+"(,)?)*\}} $output threads]} {
57
    fail "finding threads in MI output ($name)"
58
  } else {
59
    pass "finding threads in MI output ($name)"
60
 
61
    # Make list of console threads
62
    set start [expr {[string first \{ $threads] + 1}]
63
    set end   [expr {[string first \} $threads] - 1}]
64
    set threads [string range $threads $start $end]
65
    foreach thread [split $threads ,] {
66
      if {[scan $thread {thread-id="%d"} num]} {
67
        lappend thread_list $num
68
      }
69
    }
70
  }
71
 
72
  return $thread_list
73
}
74
 
75
# Check that MI and the console know of the same threads.
76
# Appends NAME to all test names.
77
proc check_mi_and_console_threads {name} {
78
  global expect_out
79
 
80
  mi_gdb_test "-thread-list-ids" \
81
    {\^done,thread-ids={(thread-id="[0-9]+"(,)*)+},number-of-threads="[0-9]+"} \
82
    "-thread-list-ids ($name)"
83
  set mi_output {}
84
  if {[info exists expect_out(buffer)]} {
85
    set mi_output $expect_out(buffer)
86
  }
87
 
88
  # GDB will return a list of thread ids and some more info:
89
  #
90
  # (gdb)
91
  # -interpreter-exec console "info threads"
92
  # ~"  4 Thread 2051 (LWP 7734)  0x401166b1 in __libc_nanosleep () at __libc_nanosleep:-1"
93
  # ~"  3 Thread 1026 (LWP 7733)   () at __libc_nanosleep:-1"
94
  # ~"  2 Thread 2049 (LWP 7732)  0x401411f8 in __poll (fds=0x804bb24, nfds=1, timeout=2000) at ../sysdeps/unix/sysv/linux/poll.c:63"
95
  # ~"* 1 Thread 1024 (LWP 7731)  main (argc=1, argv=0xbfffdd94) at ../../../src/gdb/testsuite/gdb.mi/pthreads.c:160"
96
  # FIXME: kseitz/2002-09-05: Don't use the hack-cli method.
97
  mi_gdb_test "info threads" \
98
    {.*(~".*"[\r\n]*)+.*} \
99
    "info threads ($name)"
100
  set console_output {}
101
  if {[info exists expect_out(buffer)]} {
102
    set console_output $expect_out(buffer)
103
  }
104
 
105
  # Make a list of all known threads to console (gdb's thread IDs)
106
  set console_thread_list {}
107
  foreach line [split $console_output \n] {
108
    if {[string index $line 0] == "~"} {
109
      # This is a line from the console; trim off "~", " ", "*", and "\""
110
      set line [string trim $line ~\ \"\*]
111
      if {[scan $line "%d" id] == 1} {
112
        lappend console_thread_list $id
113
      }
114
    }
115
  }
116
 
117
  # Now find the result string from MI
118
  set mi_result ""
119
  foreach line [split $mi_output \n] {
120
    if {[string range $line 0 4] == "^done"} {
121
      set mi_result $line
122
    }
123
  }
124
  if {$mi_result == ""} {
125
    fail "finding MI result string ($name)"
126
  } else {
127
    pass "finding MI result string ($name)"
128
  }
129
 
130
  # Finally, extract the thread ids and compare them to the console
131
  set num_mi_threads_str ""
132
  if {![regexp {number-of-threads="[0-9]+"} $mi_result num_mi_threads_str]} {
133
    fail "finding number of threads in MI output ($name)"
134
  } else {
135
    pass "finding number of threads in MI output ($name)"
136
 
137
    # Extract the number of threads from the MI result
138
    if {![scan $num_mi_threads_str {number-of-threads="%d"} num_mi_threads]} {
139
      fail "got number of threads from MI ($name)"
140
    } else {
141
      pass "got number of threads from MI ($name)"
142
 
143
      # Check if MI and console have same number of threads
144
      if {$num_mi_threads != [llength $console_thread_list]} {
145
        fail "console and MI have same number of threads ($name)"
146
      } else {
147
        pass "console and MI have same number of threads ($name)"
148
 
149
        # Get MI thread list
150
        set mi_thread_list [get_mi_thread_list $name]
151
 
152
        # Check if MI and console have the same threads
153
        set fails 0
154
        foreach ct [lsort $console_thread_list] mt [lsort $mi_thread_list] {
155
          if {$ct != $mt} {
156
            incr fails
157
          }
158
        }
159
        if {$fails > 0} {
160
          fail "MI and console have same threads ($name)"
161
 
162
          # Send a list of failures to the log
163
          send_log "Console has thread ids: $console_thread_list\n"
164
          send_log "MI has thread ids: $mi_thread_list\n"
165
        } else {
166
          pass "MI and console have same threads ($name)"
167
        }
168
      }
169
    }
170
  }
171
}
172
 
173
#
174
# Start here
175
#
176
set testfile "pthreads"
177
set srcfile "$testfile.c"
178
set binfile "$objdir/$subdir/gdb669-$testfile"
179
 
180
set options [list debug incdir=$objdir]
181
if {[gdb_compile_pthreads "$srcdir/$subdir/$srcfile" $binfile executable $options] != "" } {
182
    return -1
183
}
184
 
185
mi_run_to_main
186
check_mi_and_console_threads "at main"
187
 
188
for {set i 0} {$i < 4} {incr i} {
189
  mi_next "next, try $i"
190
  check_mi_and_console_threads "try $i"
191
}
192
 
193
mi_gdb_exit
194
 

powered by: WebSVN 2.1.0

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