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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gdb-7.1/] [gdb/] [testsuite/] [gdb.base/] [catch-syscall.exp] - Blame information for rev 842

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 227 jeremybenn
#   Copyright 1997, 1999, 2007, 2008, 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
 
17
# This program tests the 'catch syscall' functionality.
18
#
19
# It was written by Sergio Durigan Junior 
20
# on September/2008.
21
 
22
if { [is_remote target] || ![isnative] } then {
23
    continue
24
}
25
 
26
set prms_id 0
27
set bug_id 0
28
 
29
global srcfile
30
set testfile "catch-syscall"
31
set srcfile ${testfile}.c
32
set binfile ${objdir}/${subdir}/${testfile}
33
 
34
# All (but the last) syscalls from the example code
35
# They are ordered according to the file, so do not change this.
36
set all_syscalls { "close" "chroot" }
37
set all_syscalls_numbers { }
38
# The last syscall (exit()) does not return, so
39
# we cannot expect the catchpoint to be triggered
40
# twice.  It is a special case.
41
set last_syscall "exit_group"
42
 
43
if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
44
     untested catch-syscall.exp
45
     return -1
46
}
47
 
48
# Until "catch syscall" is implemented on other targets...
49
if {![istarget "hppa*-hp-hpux*"] && ![istarget "*-linux*"]} then {
50
    continue
51
}
52
 
53
# This shall be updated whenever 'catch syscall' is implemented
54
# on some architecture.
55
#if { ![istarget "i\[34567\]86-*-linux*"]
56
if { ![istarget "x86_64-*-linux*"] && ![istarget "i\[34567\]86-*-linux*"]
57
     && ![istarget "powerpc-*-linux*"] && ![istarget "powerpc64-*-linux*"] } {
58
     continue
59
}
60
 
61
# Internal procedure used to check if, after issuing a 'catch syscall'
62
# command (without arguments), the 'info breakpoints' command displays
63
# that '"any syscall"' is to be caught.
64
proc check_info_bp_any_syscall {} {
65
    global gdb_prompt
66
 
67
    # Verifying that the catchpoint appears in the 'info breakpoints'
68
    # command, but with "".
69
    set thistest "catch syscall appears in 'info breakpoints'"
70
    gdb_test "info breakpoints" ".*catchpoint.*keep y.*syscall \"\".*" $thistest
71
}
72
 
73
# Internal procedure used to check if, after issuing a 'catch syscall X'
74
# command (with arguments), the 'info breakpoints' command displays
75
# that the syscall 'X' is to be caught.
76
proc check_info_bp_specific_syscall { syscall } {
77
    global gdb_prompt
78
 
79
    set thistest "syscall(s) $syscall appears in 'info breakpoints'"
80
    gdb_test "info breakpoints" ".*catchpoint.*keep y.*syscall(\[(\]s\[)\])? (.)?${syscall}(.)?.*" $thistest
81
}
82
 
83
# Internal procedure used to check if, after issuing a 'catch syscall X'
84
# command (with many arguments), the 'info breakpoints' command displays
85
# that the syscalls 'X' are to be caught.
86
proc check_info_bp_many_syscalls { syscalls } {
87
    global gdb_prompt
88
    set filter_str ""
89
 
90
    foreach name $syscalls {
91
      set filter_str "${filter_str}${name}, "
92
    }
93
 
94
    set filter_str [ string trimright $filter_str ", " ]
95
 
96
    set thistest "syscalls $filter_str appears in 'info breakpoints'"
97
    gdb_test "info breakpoints" ".*catchpoint.*keep y.*syscalls (.)?${filter_str}(.)?.*" $thistest
98
}
99
 
100
# This procedure checks if there was a call to a syscall.
101
proc check_call_to_syscall { syscall } {
102
    global gdb_prompt
103
 
104
    set thistest "program has called $syscall"
105
    gdb_test "continue" "Catchpoint .*(call to syscall .?${syscall}.?).*" $thistest
106
}
107
 
108
# This procedure checks if the syscall returned.
109
proc check_return_from_syscall { syscall } {
110
    global gdb_prompt
111
 
112
    set thistest "syscall $syscall has returned"
113
    gdb_test "continue" "Catchpoint .*(returned from syscall (.)?${syscall}(.)?).*" $thistest
114
}
115
 
116
# Internal procedure that performs two 'continue' commands and checks if
117
# a syscall call AND return occur.
118
proc check_continue { syscall } {
119
    global gdb_prompt
120
 
121
    # Testing if the 'continue' stops at the
122
    # specified syscall_name.  If it does, then it should
123
    # first print that the infeior has called the syscall,
124
    # and after print that the syscall has returned.
125
 
126
    # Testing if the inferiorr has called the syscall.
127
    check_call_to_syscall $syscall
128
    # And now, that the syscall has returned.
129
    check_return_from_syscall $syscall
130
}
131
 
132
# Inserts a syscall catchpoint with an argument.
133
proc insert_catch_syscall_with_arg { syscall } {
134
    global gdb_prompt
135
 
136
    # Trying to set the catchpoint
137
    set thistest "catch syscall with arguments ($syscall)"
138
    gdb_test "catch syscall $syscall" "Catchpoint .*(syscall (.)?${syscall}(.)?( \[\[0-9\]+\])?).*" $thistest
139
 
140
    check_info_bp_specific_syscall $syscall
141
}
142
 
143
# Inserts a syscall catchpoint with many arguments.
144
proc insert_catch_syscall_with_many_args { syscalls numbers } {
145
    global gdb_prompt
146
    set catch [ join $syscalls " " ]
147
    set filter_str ""
148
 
149
    foreach name $syscalls number $numbers {
150
      set filter_str "${filter_str}'${name}' \[${number}\] "
151
    }
152
 
153
    set filter_str [ string trimright $filter_str " " ]
154
 
155
    # Trying to set the catchpoint
156
    set thistest "catch syscall with arguments ($filter_str)"
157
    gdb_test "catch syscall $catch" "Catchpoint .*(syscalls (.)?${filter_str}(.)?).*" $thistest
158
 
159
    check_info_bp_many_syscalls $syscalls
160
}
161
 
162
proc check_for_program_end {} {
163
    global gdb_prompt
164
 
165
    # Deleting the catchpoints
166
    delete_breakpoints
167
 
168
    set thistest "successful program end"
169
    gdb_test "continue" "Program exited normally.*" $thistest
170
 
171
}
172
 
173
proc test_catch_syscall_without_args {} {
174
    global gdb_prompt all_syscalls last_syscall
175
 
176
    # Trying to set the syscall
177
    set thistest "setting catch syscall without arguments"
178
    gdb_test "catch syscall" "Catchpoint .*(syscall).*" $thistest
179
 
180
    check_info_bp_any_syscall
181
 
182
    # We have to check every syscall
183
    foreach name $all_syscalls {
184
        check_continue $name
185
    }
186
 
187
    # At last but not least, we check if the inferior
188
    # has called the last (exit) syscall.
189
    check_call_to_syscall $last_syscall
190
 
191
    # Now let's see if the inferior correctly finishes.
192
    check_for_program_end
193
}
194
 
195
proc test_catch_syscall_with_args {} {
196
    global gdb_prompt
197
    set syscall_name "close"
198
 
199
    insert_catch_syscall_with_arg $syscall_name
200
 
201
    # Can we continue until we catch the syscall?
202
    check_continue $syscall_name
203
 
204
    # Now let's see if the inferior correctly finishes.
205
    check_for_program_end
206
}
207
 
208
proc test_catch_syscall_with_many_args {} {
209
    global gdb_prompt all_syscalls all_syscalls_numbers
210
 
211
    insert_catch_syscall_with_many_args $all_syscalls $all_syscalls_numbers
212
 
213
    # Can we continue until we catch the syscalls?
214
    foreach name $all_syscalls {
215
        check_continue $name
216
    }
217
 
218
    # Now let's see if the inferior correctly finishes.
219
    check_for_program_end
220
}
221
 
222
proc test_catch_syscall_with_wrong_args {} {
223
    global gdb_prompt
224
    # mlock is not called from the source
225
    set syscall_name "mlock"
226
 
227
    insert_catch_syscall_with_arg $syscall_name
228
 
229
    # Now, we must verify if the program stops with a continue.
230
    # If it doesn't, everything is right (since we don't have
231
    # a syscall named "mlock" in it).  Otherwise, this is a failure.
232
    set thistest "catch syscall with unused syscall ($syscall_name)"
233
    gdb_test "continue" "Program exited normally.*" $thistest
234
}
235
 
236
proc test_catch_syscall_restarting_inferior {} {
237
    global gdb_prompt
238
    set syscall_name "chroot"
239
 
240
    insert_catch_syscall_with_arg $syscall_name
241
 
242
    # Let's first reach the call of the syscall.
243
    check_call_to_syscall $syscall_name
244
 
245
    # Now, restart the program
246
    rerun_to_main
247
 
248
    # And check for call/return
249
    check_continue $syscall_name
250
 
251
    # Can we finish?
252
    check_for_program_end
253
}
254
 
255
proc test_catch_syscall_fail_nodatadir {} {
256
    global gdb_prompt
257
 
258
    # Sanitizing.
259
    delete_breakpoints
260
 
261
    # Make sure GDB doesn't load the syscalls xml from the system data
262
    # directory.
263
    gdb_test "set data-directory /the/path/to/nowhere" ""
264
 
265
    # Testing to see if we receive a warning when calling "catch syscall"
266
    # without XML support (without datadir).
267
    set thistest "Catch syscall displays a warning when there is no XML support (no datadir set)"
268
    gdb_test "catch syscall" "warning: Could not load the syscall XML file.*warning: GDB will not be able to display syscall names nor to verify if.*any provided syscall numbers are valid.*Catchpoint .*(syscall).*" $thistest
269
 
270
    # Since the catchpoint was set, we must check if it's present at
271
    # "info breakpoints"
272
    check_info_bp_any_syscall
273
 
274
    # Sanitizing.
275
    delete_breakpoints
276
}
277
 
278
proc do_syscall_tests {} {
279
    global gdb_prompt srcdir
280
 
281
    # First, we need to set GDB datadir.
282
    send_gdb "set data-directory $srcdir/..\n"
283
    gdb_expect 10 {
284
        -re "$gdb_prompt $" {
285
            verbose "Setting GDB datadir to $srcdir/..." 2
286
        }
287
        timeout {
288
            error "Couldn't set GDB datadir."
289
        }
290
    }
291
 
292
    # Verify that the 'catch syscall' help is available
293
    set thistest "help catch syscall"
294
    gdb_test "help catch syscall" "Catch system calls.*" $thistest
295
 
296
    # Try to set a catchpoint to a nonsense syscall
297
    set thistest "catch syscall to a nonsense syscall is prohibited"
298
    gdb_test "catch syscall nonsense_syscall" "Unknown syscall name .*" $thistest
299
 
300
    # Testing the 'catch syscall' command without arguments.
301
    # This test should catch any syscalls.
302
    if [runto_main] then { test_catch_syscall_without_args }
303
 
304
    # Testing the 'catch syscall' command with arguments.
305
    # This test should only catch the specified syscall.
306
    if [runto_main] then { test_catch_syscall_with_args }
307
 
308
    # Testing the 'catch syscall' command with many arguments.
309
    # This test should catch $all_syscalls.
310
    if [runto_main] then { test_catch_syscall_with_many_args }
311
 
312
    # Testing the 'catch syscall' command with WRONG arguments.
313
    # This test should not trigger any catchpoints.
314
    if [runto_main] then { test_catch_syscall_with_wrong_args }
315
 
316
    # Testing the 'catch' syscall command during a restart of
317
    # the inferior.
318
    if [runto_main] then { test_catch_syscall_restarting_inferior }
319
}
320
 
321
proc test_catch_syscall_without_args_noxml {} {
322
    # We will need the syscall names even not using it
323
    # because we need to know know many syscalls are in
324
    # the example file.
325
    global gdb_prompt all_syscalls last_syscall
326
 
327
    delete_breakpoints
328
 
329
    set thistest "Catch syscall without arguments and without XML support"
330
    gdb_test "catch syscall" "Catchpoint .*(syscall).*"
331
 
332
    # Now, we should be able to set a catchpoint,
333
    # and GDB shall not display the warning anymore.
334
    foreach name $all_syscalls {
335
        # Unfortunately, we don't know the syscall number
336
        # that will be caught because this information is
337
        # arch-dependent.  Thus, we try to catch anything
338
        # similar to a number.
339
        check_continue "\[0-9\]*"
340
    }
341
 
342
    # At last but not least, we check if the inferior
343
    # has called the last (exit) syscall.
344
    check_call_to_syscall "\[0-9\]*"
345
 
346
    delete_breakpoints
347
}
348
 
349
proc test_catch_syscall_with_args_noxml {} {
350
    global gdb_prompt
351
 
352
    # The number of the "close" syscall.  This is our
353
    # option for a "long-estabilished" syscall in all
354
    # Linux architectures, but unfortunately x86_64 and
355
    # a few other platforms don't "follow the convention".
356
    # Because of this, we need this ugly check :-(.
357
    set close_number ""
358
    if { [istarget "x86_64-*-linux*"] } {
359
        set close_number "3"
360
    } else {
361
        set close_number "6"
362
    }
363
 
364
    delete_breakpoints
365
 
366
    insert_catch_syscall_with_arg $close_number
367
 
368
    check_continue $close_number
369
 
370
    delete_breakpoints
371
}
372
 
373
proc test_catch_syscall_with_wrong_args_noxml {} {
374
    global gdb_prompt
375
 
376
    delete_breakpoints
377
 
378
    # Even without XML support, GDB should not accept unknown
379
    # syscall names for the catchpoint.
380
    set thistest "Catch a nonsense syscall without XML support"
381
    gdb_test "catch syscall nonsense_syscall" "Unknown syscall name .nonsense_syscall.*" $thistest
382
 
383
    delete_breakpoints
384
}
385
 
386
proc do_syscall_tests_without_xml {} {
387
    global gdb_prompt srcdir
388
 
389
    # Make sure GDB doesn't load the syscalls xml from the system data
390
    # directory.
391
    gdb_test "set data-directory /the/path/to/nowhere" ""
392
 
393
    # Let's test if we can catch syscalls without XML support.
394
    # We should succeed, but GDB is not supposed to print syscall names.
395
    if [runto_main] then { test_catch_syscall_without_args_noxml }
396
 
397
    # The only valid argument "catch syscall" should accept is the
398
    # syscall number, and not the name (since it can't translate a
399
    # name to a number).
400
    #
401
    # It's worth mentioning that we only try to catch the syscall
402
    # close().  This is because the syscall number is an arch-dependent
403
    # information, so we can't assume that we know every syscall number
404
    # in this system.  Therefore, we have decided to use a "long-estabilished"
405
    # system call, and close() just sounded the right choice :-).
406
    if [runto_main] then { test_catch_syscall_with_args_noxml }
407
 
408
    # Now, we'll try to provide a syscall name (valid or not) to the command,
409
    # and expect it to fail.
410
    if [runto_main] then { test_catch_syscall_with_wrong_args_noxml }
411
}
412
 
413
# This procedure fills the vector "all_syscalls_numbers" with the proper
414
# numbers for the used syscalls according to the architecture.
415
proc fill_all_syscalls_numbers {} {
416
    global all_syscalls_numbers
417
 
418
    # For Linux on x86, PPC and PPC64, the numbers for the syscalls "close" and
419
    # "chroot" are the same.
420
    if { ![istarget "i\[34567\]86-*-linux*"]
421
         || ![istarget "powerpc-*-linux*"] || ![istarget "powerpc64-*-linux*"] } {
422
         set all_syscalls_numbers { "6" "61" }
423
    }
424
}
425
 
426
# Start with a fresh gdb
427
 
428
gdb_exit
429
set do_xml_test ![gdb_skip_xml_test]
430
gdb_start
431
gdb_reinitialize_dir $srcdir/$subdir
432
gdb_load ${binfile}
433
 
434
# Execute the tests, using XML support
435
if $do_xml_test {
436
  do_syscall_tests
437
 
438
  # Now, we have to see if GDB displays a warning when we
439
  # don't set the data-directory but try to use catch syscall
440
  # anyway.  For that, we must restart GDB first.
441
  gdb_exit
442
  gdb_start
443
  gdb_reinitialize_dir $srcdir/$subdir
444
  gdb_load ${binfile}
445
  test_catch_syscall_fail_nodatadir
446
}
447
 
448
# Restart gdb
449
 
450
gdb_exit
451
gdb_start
452
gdb_reinitialize_dir $srcdir/$subdir
453
gdb_load ${binfile}
454
 
455
# Execute the tests, without XML support.  In this case, GDB will
456
# only display syscall numbers, and not syscall names.
457
do_syscall_tests_without_xml

powered by: WebSVN 2.1.0

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