From d9b0556e7b536024c8f7767553e7398df7a5902d Mon Sep 17 00:00:00 2001
From: Ron Williams <ron.williams.redox@gmail.com>
Date: Thu, 11 Jan 2024 06:27:28 -0800
Subject: [PATCH] add backtrace script and improve config file instructions

---
 config/aarch64/desktop-minimal.toml | 11 +++++
 config/aarch64/server-minimal.toml  | 11 +++++
 config/i686/desktop-minimal.toml    | 11 +++++
 config/i686/desktop.toml            | 11 +++++
 config/i686/dev.toml                | 11 +++++
 config/i686/server-minimal.toml     | 11 +++++
 config/i686/server.toml             | 11 +++++
 config/x86_64/desktop-contain.toml  | 11 +++++
 config/x86_64/desktop-minimal.toml  | 11 +++++
 config/x86_64/desktop.toml          | 11 +++++
 config/x86_64/dev.toml              | 11 +++++
 config/x86_64/server-minimal.toml   | 11 +++++
 config/x86_64/server.toml           | 11 +++++
 scripts/backtrace.sh                | 75 +++++++++++++++++++++++++++++
 14 files changed, 218 insertions(+)
 create mode 100755 scripts/backtrace.sh

diff --git a/config/aarch64/desktop-minimal.toml b/config/aarch64/desktop-minimal.toml
index 9f2c124e2..c2db3ecae 100644
--- a/config/aarch64/desktop-minimal.toml
+++ b/config/aarch64/desktop-minimal.toml
@@ -1,3 +1,14 @@
 # Default desktop configuration
 
 include = ["../desktop-minimal.toml"]
+
+# Override the default settings here
+
+# General settings
+[general]
+# Filesystem size in MiB
+# filesystem_size = 1024
+
+# Package settings
+[packages]
+# example = {}
\ No newline at end of file
diff --git a/config/aarch64/server-minimal.toml b/config/aarch64/server-minimal.toml
index 0649e0b94..d6c1237b5 100644
--- a/config/aarch64/server-minimal.toml
+++ b/config/aarch64/server-minimal.toml
@@ -1,3 +1,14 @@
 # Minimal configuration
 
 include = ["../server-minimal.toml"]
+
+# Override the default settings here
+
+# General settings
+[general]
+# Filesystem size in MiB
+# filesystem_size = 1024
+
+# Package settings
+[packages]
+# example = {}
\ No newline at end of file
diff --git a/config/i686/desktop-minimal.toml b/config/i686/desktop-minimal.toml
index 9f2c124e2..c2db3ecae 100644
--- a/config/i686/desktop-minimal.toml
+++ b/config/i686/desktop-minimal.toml
@@ -1,3 +1,14 @@
 # Default desktop configuration
 
 include = ["../desktop-minimal.toml"]
+
+# Override the default settings here
+
+# General settings
+[general]
+# Filesystem size in MiB
+# filesystem_size = 1024
+
+# Package settings
+[packages]
+# example = {}
\ No newline at end of file
diff --git a/config/i686/desktop.toml b/config/i686/desktop.toml
index 0cfd7c321..5b89db83b 100644
--- a/config/i686/desktop.toml
+++ b/config/i686/desktop.toml
@@ -1,3 +1,14 @@
 # Default desktop configuration
 
 include = ["../desktop.toml"]
+
+# Override the default settings here
+
+# General settings
+[general]
+# Filesystem size in MiB
+# filesystem_size = 1024
+
+# Package settings
+[packages]
+# example = {}
\ No newline at end of file
diff --git a/config/i686/dev.toml b/config/i686/dev.toml
index d5186d709..4dcc8412c 100644
--- a/config/i686/dev.toml
+++ b/config/i686/dev.toml
@@ -1,3 +1,14 @@
 # Configuration for development, includes cargo and rustc
 
 include = ["../dev.toml"]
+
+# Override the default settings here
+
+# General settings
+[general]
+# Filesystem size in MiB
+# filesystem_size = 1024
+
+# Package settings
+[packages]
+# example = {}
\ No newline at end of file
diff --git a/config/i686/server-minimal.toml b/config/i686/server-minimal.toml
index 0649e0b94..d6c1237b5 100644
--- a/config/i686/server-minimal.toml
+++ b/config/i686/server-minimal.toml
@@ -1,3 +1,14 @@
 # Minimal configuration
 
 include = ["../server-minimal.toml"]
+
+# Override the default settings here
+
+# General settings
+[general]
+# Filesystem size in MiB
+# filesystem_size = 1024
+
+# Package settings
+[packages]
+# example = {}
\ No newline at end of file
diff --git a/config/i686/server.toml b/config/i686/server.toml
index c0269cc00..ee6eed7c5 100644
--- a/config/i686/server.toml
+++ b/config/i686/server.toml
@@ -1,3 +1,14 @@
 # Default server configuration
 
 include = ["../server.toml"]
+
+# Override the default settings here
+
+# General settings
+[general]
+# Filesystem size in MiB
+# filesystem_size = 1024
+
+# Package settings
+[packages]
+# example = {}
\ No newline at end of file
diff --git a/config/x86_64/desktop-contain.toml b/config/x86_64/desktop-contain.toml
index f57dbb247..8e32a39fd 100644
--- a/config/x86_64/desktop-contain.toml
+++ b/config/x86_64/desktop-contain.toml
@@ -2,6 +2,17 @@
 
 include = ["../desktop.toml"]
 
+# Override the default settings here
+
+# General settings
+[general]
+# Filesystem size in MiB
+# filesystem_size = 1024
+
+# Package settings
+[packages]
+# example = {}
+
 # Override orbital init to use contain_orblogin
 [[files]]
 path = "/etc/init.d/20_orbital"
diff --git a/config/x86_64/desktop-minimal.toml b/config/x86_64/desktop-minimal.toml
index 9f2c124e2..c2db3ecae 100644
--- a/config/x86_64/desktop-minimal.toml
+++ b/config/x86_64/desktop-minimal.toml
@@ -1,3 +1,14 @@
 # Default desktop configuration
 
 include = ["../desktop-minimal.toml"]
+
+# Override the default settings here
+
+# General settings
+[general]
+# Filesystem size in MiB
+# filesystem_size = 1024
+
+# Package settings
+[packages]
+# example = {}
\ No newline at end of file
diff --git a/config/x86_64/desktop.toml b/config/x86_64/desktop.toml
index 0cfd7c321..5b89db83b 100644
--- a/config/x86_64/desktop.toml
+++ b/config/x86_64/desktop.toml
@@ -1,3 +1,14 @@
 # Default desktop configuration
 
 include = ["../desktop.toml"]
+
+# Override the default settings here
+
+# General settings
+[general]
+# Filesystem size in MiB
+# filesystem_size = 1024
+
+# Package settings
+[packages]
+# example = {}
\ No newline at end of file
diff --git a/config/x86_64/dev.toml b/config/x86_64/dev.toml
index d5186d709..4dcc8412c 100644
--- a/config/x86_64/dev.toml
+++ b/config/x86_64/dev.toml
@@ -1,3 +1,14 @@
 # Configuration for development, includes cargo and rustc
 
 include = ["../dev.toml"]
+
+# Override the default settings here
+
+# General settings
+[general]
+# Filesystem size in MiB
+# filesystem_size = 1024
+
+# Package settings
+[packages]
+# example = {}
\ No newline at end of file
diff --git a/config/x86_64/server-minimal.toml b/config/x86_64/server-minimal.toml
index 0649e0b94..d6c1237b5 100644
--- a/config/x86_64/server-minimal.toml
+++ b/config/x86_64/server-minimal.toml
@@ -1,3 +1,14 @@
 # Minimal configuration
 
 include = ["../server-minimal.toml"]
+
+# Override the default settings here
+
+# General settings
+[general]
+# Filesystem size in MiB
+# filesystem_size = 1024
+
+# Package settings
+[packages]
+# example = {}
\ No newline at end of file
diff --git a/config/x86_64/server.toml b/config/x86_64/server.toml
index c0269cc00..ee6eed7c5 100644
--- a/config/x86_64/server.toml
+++ b/config/x86_64/server.toml
@@ -1,3 +1,14 @@
 # Default server configuration
 
 include = ["../server.toml"]
+
+# Override the default settings here
+
+# General settings
+[general]
+# Filesystem size in MiB
+# filesystem_size = 1024
+
+# Package settings
+[packages]
+# example = {}
\ No newline at end of file
diff --git a/scripts/backtrace.sh b/scripts/backtrace.sh
new file mode 100755
index 000000000..02e88017d
--- /dev/null
+++ b/scripts/backtrace.sh
@@ -0,0 +1,75 @@
+#!/usr/bin/env bash
+
+usage()
+{
+    echo "Usage: $0 -r recipe [ -e command_name ] [ -R ] [ -X | -6 | -A ] [[ -b backtracefile ] | [ addr1 ... ]]"
+    echo
+    echo "Print the backtrace contained in the backtracefile."
+    echo "Symbols are taken from the executable for the given recipe."
+    echo "If no backtracefile is given, decode the given addresses instead."
+    echo "This command must be run in the 'redox' directory."
+    echo
+    echo "-X for x86_64, -6 for i686, -A for aarch64 (x86_64 is the default)."
+    echo "To read from stdin, use '-b -'"
+    echo "The name of the executable must match what Cargo believes it to be."
+    echo "If the executalbe is named 'recipe_command', just use 'command' as the name."
+    echo "The debug version of the executable is used if available."
+    echo "The release version is used if no debug version exists."
+    echo "-R to force the use of the 'release' version of the executable."
+    echo "Make sure the executable is the one that produced the backtrace."
+    exit 1
+}
+
+ARCH="x86_64"
+
+while getopts ":b:e:r:hRXA6" opt
+do
+    case "$opt" in
+        X) ARCH="x86_64";;
+        A) ARCH="aarch64";;
+        6) ARCH="i686";;
+        b) INFILE="$OPTARG";;
+        e) COMMAND="$OPTARG";;
+        i) INST="$OPTARG";;
+        r) RECIPE_NAME="$OPTARG";;
+        R) RELEASE=true;;
+	h) usage;;
+	\?) echo "Unknown option -$OPTARG, try -h for help"; exit;;
+        :) echo "-$OPTARG requires a value"; exit;;
+	esac
+done
+shift $((OPTIND -1))
+
+if [ -z "$RECIPE_NAME" ]
+then
+    usage
+fi
+
+if [ -z "$INFILE" -a $# = 0 ]
+then
+    usage
+fi
+
+# if no command name is given, assume it's the same as the recipe name
+RECIPE_DIR="$(cd cookbook; target/release/find_recipe $RECIPE_NAME)"
+if [ -z "$COMMAND" ]
+then
+    COMMAND="$RECIPE_NAME"
+fi
+
+# look for the debug version of the command
+EXECUTABLE=cookbook/"$RECIPE_DIR"/target/"$ARCH"-unknown-redox/build/target/"$ARCH"-unknown-redox/debug/"$COMMAND"
+
+# try the release version next
+if [ ! -f "$EXECUTABLE" -o ! -z "$RELEASE" ]
+then
+    EXECUTABLE=cookbook/"$RECIPE_DIR"/target/"$ARCH"-unknown-redox/build/target/"$ARCH"-unknown-redox/release/"$COMMAND"
+fi
+
+if [ $# -ne 0 ]
+then
+    addr2line --demangle=rust --inlines --pretty-print --functions --exe="$EXECUTABLE" $@
+else
+    sed '/^\s*$/d; s/^.*0x\([0-9a-f]*\).*$/\1/g' "$INFILE" | addr2line --demangle=rust --inlines --pretty-print --functions --exe="$EXECUTABLE"
+fi
+
-- 
GitLab