Skip to content

Commit

Permalink
util (ble-stackdump): fix a shift of line numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Apr 18, 2020
1 parent 04da4dd commit a14b72f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
3 changes: 2 additions & 1 deletion memo/ChangeLog.md
Expand Up @@ -22,7 +22,7 @@
- edit: support Bash 5.1 `READLINE_MARK` and `PROMPT_COMMANDS` `#D1328` e97a858
- syntax: support confusing parameter expansions like `${#@}`, etc. `#D1330` b7b42eb
- contrib: add contrib for user settings `#D1335` f290115
- syntax: support `${var@UuLK}` in Bash 5.1 `#D1336` 0000000
- syntax: support `${var@UuLK}` in Bash 5.1 `#D1336` 04da4dd

## Changes

Expand Down Expand Up @@ -80,6 +80,7 @@
- edit: fix a bug that `set +H` is cancelled on command execution `#D1332` 02bdf4e
- syntax (`ble/syntax/parse/shift`): fix a bug of shift skip in nested words `#D1333` 65fbba0
- global: work around Bash-4.4 `return` in trap handlers `#D1334` aa09d15
- util (`ble-stackdump`): fix a shift of line numbers `#D1337` 0000000

## Compatibility

Expand Down
20 changes: 20 additions & 0 deletions memo/D1337.sh
@@ -0,0 +1,20 @@
#!/bin/bash

f1() {
local message='hello world'
ble-stackdump "$message"
}

f2() {
local dummy=1
f1
output=$dummy
}

f3() {
local input=$1 output=
f2
ret=$output
}

f3
5 changes: 5 additions & 0 deletions note.txt
Expand Up @@ -2915,6 +2915,11 @@ bash_tips

2020-04-19

* ble-stackdump の開始フレームがずれている [#D1337]
ble/util/stackdump という内部実装に分けた為である。
分ける必要があっただろうか。或いは、開始フレームを外から変更できる様にする?
後、BASH_LINENO の参照を誤っている。取り敢えず修正した。

* syntax: 変数展開で bash-5.1 で UuLK という operator が追加されている [#D1336]
というより、bash-4.3 では operator は無効にするべきでは。
→確かめてみた所ちゃんとその様な実装になっていた。
Expand Down
14 changes: 8 additions & 6 deletions src/util.sh
Expand Up @@ -2742,14 +2742,15 @@ function ble-import {
## スタック情報の前に表示するタイトルを指定します。
##
_ble_util_stackdump_title=stackdump
_ble_util_stackdump_start=
function ble/util/stackdump {
((bleopt_internal_stackdump_enabled)) || return 1
local message=$1
local i nl=$'\n'
local message="$_ble_term_sgr0$_ble_util_stackdump_title: $message$nl"
local iarg=$BASH_ARGC args= extdebug=
local message=$1 nl=$'\n'
message="$_ble_term_sgr0$_ble_util_stackdump_title: $message$nl"
local extdebug=1 iarg=$BASH_ARGC args=
shopt -q extdebug 2>/dev/null && extdebug=1
for ((i=1;i<${#FUNCNAME[*]};i++)); do
local i i0=${_ble_util_stackdump_start:-1} iN=${#FUNCNAME[*]}
for ((i=i0;i<iN;i++)); do
if [[ $extdebug ]] && ((BASH_ARGC[i])); then
args=("${BASH_ARGV[@]:iarg:BASH_ARGC[i]}")
ble/array#reverse args
Expand All @@ -2758,7 +2759,7 @@ function ble/util/stackdump {
else
args=
fi
message="$message @ ${BASH_SOURCE[i]}:${BASH_LINENO[i]} (${FUNCNAME[i]}$args)$nl"
message="$message @ ${BASH_SOURCE[i]}:${BASH_LINENO[i-1]} (${FUNCNAME[i]}$args)$nl"
done
ble/util/put "$message"
}
Expand All @@ -2775,6 +2776,7 @@ function ble-stackdump {
return 0
fi

local _ble_util_stackdump_start=2
ble/util/stackdump "${args[*]}"
}

Expand Down

0 comments on commit a14b72f

Please sign in to comment.