]> git.lizzy.rs Git - rust.git/commitdiff
debuginfo: Add script that allows to conveniently start LLDB in "rust-mode"
authorMichael Woerister <michaelwoerister@posteo>
Thu, 13 Nov 2014 16:25:15 +0000 (17:25 +0100)
committerMichael Woerister <michaelwoerister@posteo>
Wed, 26 Nov 2014 14:58:17 +0000 (15:58 +0100)
Makefile.in
mk/clean.mk
mk/debuggers.mk [new file with mode: 0644]
mk/main.mk
mk/prepare.mk
src/etc/rust-lldb [new file with mode: 0755]

index 48b211167cf18736e976d22f546e232110fdc7e9..17ae845bf0773da92ce98f685375a92e3e709b2f 100644 (file)
@@ -198,6 +198,8 @@ include $(CFG_SRC_DIR)mk/rustllvm.mk
 include $(CFG_SRC_DIR)mk/docs.mk
 # LLVM
 include $(CFG_SRC_DIR)mk/llvm.mk
+# Rules for installing debugger scripts
+include $(CFG_SRC_DIR)mk/debuggers.mk
 
 ######################################################################
 # Secondary makefiles, conditionalized for speed
index 97c823c9e2de936ac427cd5fa819370064580754..aadc55ba6c4977dda86d5e5567c1ea6a8681b108 100644 (file)
@@ -63,6 +63,7 @@ clean-generic-$(2)-$(1):
          -name '*.lib' -o \
          -name '*.dll' -o \
          -name '*.def' -o \
+         -name '*.py' -o \
          -name '*.bc' \
          \) \
          | xargs rm -f
@@ -78,7 +79,7 @@ define CLEAN_HOST_STAGE_N
 
 clean$(1)_H_$(2): \
            $$(foreach crate,$$(CRATES),clean$(1)_H_$(2)-lib-$$(crate)) \
-           $$(foreach tool,$$(TOOLS),clean$(1)_H_$(2)-tool-$$(tool))
+           $$(foreach tool,$$(TOOLS) $$(DEBUGGER_BIN_SCRIPTS),clean$(1)_H_$(2)-tool-$$(tool))
        $$(Q)rm -fr $(2)/rt/libbacktrace
 
 clean$(1)_H_$(2)-tool-%:
@@ -98,7 +99,7 @@ define CLEAN_TARGET_STAGE_N
 
 clean$(1)_T_$(2)_H_$(3): \
            $$(foreach crate,$$(CRATES),clean$(1)_T_$(2)_H_$(3)-lib-$$(crate)) \
-           $$(foreach tool,$$(TOOLS),clean$(1)_T_$(2)_H_$(3)-tool-$$(tool))
+           $$(foreach tool,$$(TOOLS) $$(DEBUGGER_BIN_SCRIPTS),clean$(1)_T_$(2)_H_$(3)-tool-$$(tool))
        $$(Q)rm -f $$(TLIB$(1)_T_$(2)_H_$(3))/libmorestack.a
        $$(Q)rm -f $$(TLIB$(1)_T_$(2)_H_$(3))/libcompiler-rt.a
        $(Q)rm -f $$(TLIB$(1)_T_$(2)_H_$(3))/librun_pass_stage* # For unix
diff --git a/mk/debuggers.mk b/mk/debuggers.mk
new file mode 100644 (file)
index 0000000..54955f0
--- /dev/null
@@ -0,0 +1,59 @@
+# Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+# file at the top-level directory of this distribution and at
+# http://rust-lang.org/COPYRIGHT.
+#
+# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+# option. This file may not be copied, modified, or distributed
+# except according to those terms.
+
+######################################################################
+# Copy debugger related scripts
+######################################################################
+
+DEBUGGER_RUSTLIB_ETC_SCRIPTS=lldb_rust_formatters.py
+DEBUGGER_BIN_SCRIPTS=rust-lldb
+
+DEBUGGER_RUSTLIB_ETC_SCRIPTS_ABS=$(foreach script,$(DEBUGGER_RUSTLIB_ETC_SCRIPTS), \
+                                     $(CFG_SRC_DIR)src/etc/$(script))
+DEBUGGER_BIN_SCRIPTS_ABS=$(foreach script,$(DEBUGGER_BIN_SCRIPTS), \
+                             $(CFG_SRC_DIR)src/etc/$(script))
+
+DEBUGGER_SCRIPTS_ALL=$(DEBUGGER_RUSTLIB_ETC_SCRIPTS_ABS) $(DEBUGGER_BIN_SCRIPTS_ABS)
+
+# $(1) - the stage to copy to
+# $(2) - the host triple
+define DEF_INSTALL_DEBUGGER_SCRIPTS_HOST
+
+tmp/install-debugger-scripts$(1)_H_$(2).done: $$(DEBUGGER_SCRIPTS_ALL)
+       $(Q)mkdir -p $$(HBIN$(1)_H_$(2))
+       $(Q)mkdir -p $$(HLIB$(1)_H_$(2))/rustlib/etc
+       $(Q)install $(DEBUGGER_BIN_SCRIPTS_ABS) $$(HBIN$(1)_H_$(2))
+       $(Q)install $(DEBUGGER_RUSTLIB_ETC_SCRIPTS_ABS) $$(HLIB$(1)_H_$(2))/rustlib/etc
+       $(Q)touch $$@
+endef
+
+# Expand host make-targets for all stages
+$(foreach stage,$(STAGES), \
+  $(foreach host,$(CFG_HOST), \
+    $(eval $(call DEF_INSTALL_DEBUGGER_SCRIPTS_HOST,$(stage),$(host)))))
+
+# $(1) is the stage number
+# $(2) is the target triple
+# $(3) is the host triple
+define DEF_INSTALL_DEBUGGER_SCRIPTS_TARGET
+
+tmp/install-debugger-scripts$(1)_T_$(2)_H_$(3).done: $$(DEBUGGER_SCRIPTS_ALL)
+       $(Q)mkdir -p $$(TBIN$(1)_T_$(2)_H_$(3))
+       $(Q)mkdir -p $$(TLIB$(1)_T_$(2)_H_$(3))/rustlib/etc
+       $(Q)install $(DEBUGGER_BIN_SCRIPTS_ABS) $$(TBIN$(1)_T_$(2)_H_$(3))
+       $(Q)install $(DEBUGGER_RUSTLIB_ETC_SCRIPTS_ABS) $$(TLIB$(1)_T_$(2)_H_$(3))/rustlib/etc
+       $(Q)touch $$@
+endef
+
+# Expand target make-targets for all stages
+$(foreach stage,$(STAGES), \
+  $(foreach target,$(CFG_TARGET), \
+    $(foreach host,$(CFG_HOST), \
+      $(eval $(call DEF_INSTALL_DEBUGGER_SCRIPTS_TARGET,$(stage),$(target),$(host))))))
index a9a99f132fba4ade0391aeeeb12f2e749da62058..4aed1cea9ca0987dd637ffbdd1a5fdac70e2307c 100644 (file)
@@ -356,7 +356,8 @@ HSREQ$(1)_H_$(3) = $$(HBIN$(1)_H_$(3))/rustc$$(X_$(3))
 else
 HSREQ$(1)_H_$(3) = \
        $$(HBIN$(1)_H_$(3))/rustc$$(X_$(3)) \
-       $$(MKFILE_DEPS)
+       $$(MKFILE_DEPS) \
+       tmp/install-debugger-scripts$(1)_H_$(3).done
 endif
 
 # Prerequisites for using the stageN compiler to build target artifacts
@@ -370,7 +371,8 @@ TSREQ$(1)_T_$(2)_H_$(3) = \
 SREQ$(1)_T_$(2)_H_$(3) = \
        $$(TSREQ$(1)_T_$(2)_H_$(3)) \
        $$(foreach dep,$$(TARGET_CRATES), \
-           $$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$$(dep))
+           $$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$$(dep)) \
+       tmp/install-debugger-scripts$(1)_T_$(2)_H_$(3).done
 
 # Prerequisites for a working stageN compiler and complete set of target
 # libraries
index 7df2489744b6707bfd5ba7c2811bc87593d157fe..d404d3d2950e04a931740f3e926975ad4f97efd2 100644 (file)
@@ -155,7 +155,7 @@ prepare-base-$(1): PREPARE_DEST_LIB_DIR=$$(PREPARE_DEST_DIR)/$$(CFG_LIBDIR_RELAT
 prepare-base-$(1): PREPARE_DEST_MAN_DIR=$$(PREPARE_DEST_DIR)/share/man/man1
 prepare-base-$(1): prepare-everything-$(1)
 
-prepare-everything-$(1): prepare-host-$(1) prepare-targets-$(1)
+prepare-everything-$(1): prepare-host-$(1) prepare-targets-$(1) prepare-debugger-scripts-$(1)
 
 prepare-host-$(1): prepare-host-tools-$(1)
 
@@ -167,8 +167,13 @@ prepare-host-tools-$(1): \
 prepare-host-dirs-$(1): prepare-maybe-clean-$(1)
        $$(call PREPARE_DIR,$$(PREPARE_DEST_BIN_DIR))
        $$(call PREPARE_DIR,$$(PREPARE_DEST_LIB_DIR))
+       $$(call PREPARE_DIR,$$(PREPARE_DEST_LIB_DIR)/rustlib/etc)
        $$(call PREPARE_DIR,$$(PREPARE_DEST_MAN_DIR))
 
+prepare-debugger-scripts-$(1): prepare-host-dirs-$(1) $(DEBUGGER_SCRIPTS_ALL)
+       $$(Q)$$(PREPARE_BIN_CMD) $(DEBUGGER_BIN_SCRIPTS_ABS) $$(PREPARE_DEST_BIN_DIR)
+       $$(Q)$$(PREPARE_LIB_CMD) $(DEBUGGER_RUSTLIB_ETC_SCRIPTS_ABS) $$(PREPARE_DEST_LIB_DIR)/rustlib/etc
+
 $$(foreach tool,$$(PREPARE_TOOLS), \
   $$(foreach host,$$(CFG_HOST), \
       $$(eval $$(call DEF_PREPARE_HOST_TOOL,$$(tool),$$(PREPARE_STAGE),$$(host),$(1)))))
diff --git a/src/etc/rust-lldb b/src/etc/rust-lldb
new file mode 100755 (executable)
index 0000000..19f36df
--- /dev/null
@@ -0,0 +1,30 @@
+#!/bin/sh
+# Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+# file at the top-level directory of this distribution and at
+# http://rust-lang.org/COPYRIGHT.
+#
+# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+# option. This file may not be copied, modified, or distributed
+# except according to those terms.
+
+# Exit if anything fails
+set -e
+
+# Create a tempfile containing the LLDB script we want to execute on startup
+TMPFILE=`mktemp /tmp/rust-lldb-commands.XXXXXX`
+
+# Make sure to delete the tempfile no matter what
+trap "rm -f $TMPFILE; exit" INT TERM EXIT
+
+# Find out where to look for the pretty printer Python module
+RUSTC_SYSROOT=`rustc -Zprint-sysroot`
+
+# Write the LLDB script to the tempfile
+echo "command script import \"$RUSTC_SYSROOT/lib/rustlib/etc/lldb_rust_formatters.py\"" >> $TMPFILE
+echo "type summary add --no-value --python-function lldb_rust_formatters.print_val -x \".*\" --category Rust" >> $TMPFILE
+echo "type category enable Rust" >> $TMPFILE
+
+# Call LLDB with the script added to the argument list
+lldb --source-before-file="$TMPFILE" "$@"