Matthew Maurer | 5423635 | 2020-04-22 09:37:40 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | # Exit if anything fails |
| 4 | set -e |
| 5 | |
| 6 | # Find the host triple so we can find lldb in rustlib. |
| 7 | host=$(rustc -vV | sed -n -e 's/^host: //p') |
| 8 | |
| 9 | # Find out where to look for the pretty printer Python module |
| 10 | RUSTC_SYSROOT=$(rustc --print sysroot) |
| 11 | RUST_LLDB="$RUSTC_SYSROOT/lib/rustlib/$host/bin/lldb" |
| 12 | |
| 13 | lldb=lldb |
| 14 | if [ -f "$RUST_LLDB" ]; then |
| 15 | lldb="$RUST_LLDB" |
| 16 | else |
| 17 | if ! command -v "$lldb" > /dev/null; then |
| 18 | echo "$lldb not found! Please install it." >&2 |
| 19 | exit 1 |
| 20 | else |
| 21 | LLDB_VERSION=$("$lldb" --version | cut -d ' ' -f3) |
| 22 | |
| 23 | if [ "$LLDB_VERSION" = "3.5.0" ]; then |
| 24 | cat << EOF >&2 |
| 25 | *** |
| 26 | WARNING: This version of LLDB has known issues with Rust and cannot display the contents of local variables! |
| 27 | *** |
| 28 | EOF |
| 29 | fi |
| 30 | fi |
| 31 | fi |
| 32 | |
| 33 | # Prepare commands that will be loaded before any file on the command line has been loaded |
| 34 | script_import="command script import \"$RUSTC_SYSROOT/lib/rustlib/etc/lldb_rust_formatters.py\"" |
| 35 | category_definition="type summary add --no-value --python-function lldb_rust_formatters.print_val -x \".*\" --category Rust" |
| 36 | category_enable="type category enable Rust" |
| 37 | |
| 38 | # Call LLDB with the commands added to the argument list |
| 39 | exec "$lldb" --one-line-before-file "$script_import" \ |
| 40 | --one-line-before-file "$category_definition" \ |
| 41 | --one-line-before-file "$category_enable" \ |
| 42 | "$@" |