]> Git Repo - binutils.git/blob - gdb/testsuite/lib/rust-support.exp
Automatic date update in version.in
[binutils.git] / gdb / testsuite / lib / rust-support.exp
1 # Copyright 2016-2022 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 <http://www.gnu.org/licenses/>.
15
16 # Auxiliary function to set the language to Rust.
17 # The result is 1 (true) for success, 0 (false) for failure.
18 proc set_lang_rust {} {
19     if [gdb_test_no_output "set language rust"] {
20         return 0
21     }
22     if [gdb_test "show language" ".* source language is \"rust\"." \
23            "set language to \"rust\""] {
24         return 0
25     }
26     return 1
27 }
28
29 proc gdb_compile_rust {sources dest options} {
30     set res -1
31
32     if {[llength $sources] > 1} {
33         error "gdb rust setup can only compile one source file at a time"
34     }
35
36     global board
37     set board [target_info name]
38     set multilib_flags_orig [board_info $board multilib_flags]
39     set multilib_flags {}
40     foreach op $multilib_flags_orig {
41         # Pretend rustc supports -pie/-no-pie/-fPIE/-fno-PIE.
42         switch $op {
43             "-pie" - "-no-pie" {
44                 # Pass it to linker.
45                 lappend multilib_flags -C link-arg=$op
46             }
47             "-fno-PIE" {
48                 # Translate to rustc codegen equivalent.
49
50                 # The rustc documentation insists that we should use static
51                 # here, but that causes segfaults leading to:
52                 # UNTESTED: gdb.rust/rawids.exp: could not run to breakpoint
53                 # UNTESTED: gdb.rust/pp.exp: could not run to breakpoint
54                 # Instead, we use dynamic-no-pic which does seem to work.
55                 lappend multilib_flags -C relocation-model=dynamic-no-pic
56             }
57             "-fPIE" {
58                 # Translate to rustc codegen equivalent.
59                 lappend multilib_flags -C relocation-model=pic
60             }
61             default {
62                 # Pass unmodified.
63                 lappend multilib_flags $op
64             }
65         }
66     }
67
68     save_target_board_info { multilib_flags } {
69         unset_board_info multilib_flags
70         set_board_info multilib_flags "$multilib_flags"
71         if {[gdb_compile [lindex $sources 0] $dest executable \
72                  $options] == ""} {
73             set res ""
74         }
75     }
76
77     return $res
78 }
79
80 # Return the version of LLVM used by the Rust compiler.  Note that
81 # older versions of rustc don't print this -- in this case the
82 # returned version is "0.0".
83 gdb_caching_proc rust_llvm_version {
84     set rustc [find_rustc]
85     if {$rustc == ""} {
86         verbose "could not find rustc"
87     } else {
88         set output [lindex [remote_exec host "$rustc --version --verbose"] 1]
89         foreach line [split $output \n] {
90             if {[regexp "LLVM version: (.+)\$" $output ignore version]} {
91                 return $version
92             }
93         }
94         verbose "could not match rustc version output: $output"
95     }
96     return 0.0
97 }
98
99 # Return the version of the Rust compiler.
100 gdb_caching_proc rust_compiler_version {
101     set rustc [find_rustc]
102     if {$rustc == ""} {
103         verbose "could not find rustc"
104     } else {
105         set output [lindex [remote_exec host "$rustc --version --verbose"] 1]
106         foreach line [split $output \n] {
107             if {[regexp "rustc (\[0-9.\]+).*\$" $output ignore version]} {
108                 return $version
109             }
110         }
111         verbose "could not match rustc version output: $output"
112     }
113     return 0.0
114 }
This page took 0.030155 seconds and 4 git commands to generate.