1 # Copyright 2016-2022 Free Software Foundation, Inc.
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.
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.
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/>.
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"] {
22 if [gdb_test "show language" ".* source language is \"rust\"." \
23 "set language to \"rust\""] {
29 proc gdb_compile_rust {sources dest options} {
32 if {[llength $sources] > 1} {
33 error "gdb rust setup can only compile one source file at a time"
37 set board [target_info name]
38 set multilib_flags_orig [board_info $board multilib_flags]
40 foreach op $multilib_flags_orig {
41 # Pretend rustc supports -pie/-no-pie/-fPIE/-fno-PIE.
45 lappend multilib_flags -C link-arg=$op
48 # Translate to rustc codegen equivalent.
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
58 # Translate to rustc codegen equivalent.
59 lappend multilib_flags -C relocation-model=pic
63 lappend multilib_flags $op
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 \
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]
86 verbose "could not find rustc"
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]} {
94 verbose "could not match rustc version output: $output"
99 # Return the version of the Rust compiler.
100 gdb_caching_proc rust_compiler_version {
101 set rustc [find_rustc]
103 verbose "could not find rustc"
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]} {
111 verbose "could not match rustc version output: $output"