From: Tom de Vries Date: Tue, 14 Feb 2023 10:53:54 +0000 (+0100) Subject: [gdb/testsuite] Factor out proc linux_kernel_version X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=37d75d4552d6b4d292ffb4dee92329a449288375;p=binutils-gdb.git [gdb/testsuite] Factor out proc linux_kernel_version Factor out new proc linux_kernel_version from test-case gdb.arch/i386-pkru.exp. Tested on x86_64-linux. --- diff --git a/gdb/testsuite/gdb.arch/i386-pkru.exp b/gdb/testsuite/gdb.arch/i386-pkru.exp index 90d8c1d9d4c..1f047df68ef 100644 --- a/gdb/testsuite/gdb.arch/i386-pkru.exp +++ b/gdb/testsuite/gdb.arch/i386-pkru.exp @@ -59,20 +59,12 @@ if { !$supports_pkru } { # the PKRU using ptrace, see commit 4a804c4f8356 ("x86/fpu: Allow PKRU to be # (once again) written by ptrace."). set have_xfail 0 -if { [istarget *-*-linux*] } { - set res [remote_exec target "uname -r"] - set status [lindex $res 0] - set output [lindex $res 1] - - set re ^($decimal)\\.($decimal)\\.($decimal) - if { $status == 0 - && [regexp $re $output dummy v1 v2 v3] == 1 } { - set v [list $v1 $v2 $v3] - set have_xfail \ - [expr \ - [version_compare [list 5 14 0] <= $v] \ - && [version_compare $v < [list 6 2 0]]] - } +set v [linux_kernel_version] +if { $v != {} } { + set have_xfail \ + [expr \ + [version_compare [list 5 14 0] <= $v] \ + && [version_compare $v < [list 6 2 0]]] } # Test pkru register at startup diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index 7f98f080328..e48228ed4f6 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -9374,5 +9374,28 @@ proc has_dependency { file dep } { return [regexp $dep $output] } +# Detect linux kernel version and return as list of 3 numbers: major, minor, +# and patchlevel. On failure, return an empty list. + +gdb_caching_proc linux_kernel_version { + if { ![istarget *-*-linux*] } { + return {} + } + + set res [remote_exec target "uname -r"] + set status [lindex $res 0] + set output [lindex $res 1] + if { $status != 0 } { + return {} + } + + set re ^($::decimal)\\.($::decimal)\\.($::decimal) + if { [regexp $re $output dummy v1 v2 v3] != 1 } { + return {} + } + + return [list $v1 $v2 $v3] +} + # Always load compatibility stuff. load_lib future.exp