aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/%HOME%/.bash_utils
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2019-01-22 01:46:05 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2019-01-22 01:46:05 +0300
commit20ab6f936596bcff3a0aa8bd717e359f94dd2569 (patch)
tree7e3c585c6f07c4b88c9b391cdc5b10a44a52dd7c /%HOME%/.bash_utils
parentgit-fixup: add copyright notice (diff)
downloadlinux-home-20ab6f936596bcff3a0aa8bd717e359f94dd2569.tar.gz
linux-home-20ab6f936596bcff3a0aa8bd717e359f94dd2569.zip
cxx.sh: add apport_gdb
Diffstat (limited to '')
-rw-r--r--%HOME%/.bash_utils/cxx.sh37
-rw-r--r--%HOME%/.bash_utils/text.sh21
2 files changed, 56 insertions, 2 deletions
diff --git a/%HOME%/.bash_utils/cxx.sh b/%HOME%/.bash_utils/cxx.sh
index 402b4cc..cb55a7f 100644
--- a/%HOME%/.bash_utils/cxx.sh
+++ b/%HOME%/.bash_utils/cxx.sh
@@ -162,3 +162,40 @@ runcxx() (
runc_compiler="${runcxx_compiler:-g++}" \
runc "$@"
)
+
+apport_gdb() (
+ set -o errexit -o nounset -o pipefail
+
+ if [ "$#" -ne 1 ]; then
+ echo "usage: ${FUNCNAME[0]} BINARY" >&2
+ return 1
+ fi
+
+ local binary_path="$1"
+ binary_path="$( readlink --canonicalize-missing -- "$binary_path" )"
+
+ local crash_path
+ crash_path="$( str_replace "$binary_path" '/' '_' )"
+ crash_path="$crash_path.$UID.crash"
+ crash_path="/var/crash/$crash_path"
+
+ if [ ! -r "$crash_path" ]; then
+ echo "${FUNCNAME[0]}: $crash_path doesn't exist or isn't readable" >&2
+ return 1
+ fi
+
+ local crash_dir
+ crash_dir="$( mktemp --directory )"
+
+ local rm_crash_dir
+ rm_crash_dir="$( printf -- 'rm -rf -- %q' "$crash_dir" )"
+
+ trap "$rm_crash_dir" EXIT
+
+ apport-unpack "$crash_path" "$crash_dir"
+ gdb "$binary_path" "$crash_dir/CoreDump"
+)
+
+agdb() {
+ apport_gdb "$@"
+}
diff --git a/%HOME%/.bash_utils/text.sh b/%HOME%/.bash_utils/text.sh
index da21b5c..4bda806 100644
--- a/%HOME%/.bash_utils/text.sh
+++ b/%HOME%/.bash_utils/text.sh
@@ -65,7 +65,7 @@ _sed_escape_substitution() (
echo "$s"
)
-str_replace() (
+file_replace() (
set -o errexit -o nounset -o pipefail
if [ "$#" -lt 3 ]; then
@@ -83,7 +83,7 @@ str_replace() (
sed --binary --in-place -- "s/$old/$new/g" "$@"
)
-str_replace_word() (
+file_replace_word() (
set -o errexit -o nounset -o pipefail
if [ "$#" -lt 3 ]; then
@@ -101,6 +101,23 @@ str_replace_word() (
sed --binary --in-place -- "s/\\b$old\\b/$new/g" "$@"
)
+str_replace() (
+ set -o errexit -o nounset -o pipefail
+
+ if [ "$#" -ne 3 ]; then
+ echo "usage: ${FUNCNAME[0]} STR SUB REP" >&2
+ return 1
+ fi
+
+ local str="$1"
+ local sub="$2"
+ local rep="$3"
+
+ sub="$( _bash_escape_pattern "$sub" )"
+
+ echo "${str//$sub/$rep}"
+)
+
str_tolower() (
set -o errexit -o nounset -o pipefail