sourced files can't be always resolved
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 25/100
Research direction
Reproduce the shown script and inspect the trap handler, especially the debug output for $_Dbg_bash_command, $PWD, and BASH_SOURCE. Investigate how sourced paths are currently resolved from $_Dbg_init_cwd, $_Dbg_cdir, and $(pwd); done means reliably locating ../lib.bash after it is sourced from another working directory, including a regression test for the example.
Written by the indexing model from the issue text.
Description
Follow up to https://github.com/Trepan-Debuggers/bashdb/issues/50
I think that I have a better understanding now of what's going on.
For this script:
cd ./some-dir
. ../lib.bash
cd ~
function_from_lib.bash
The trap handler invoked when function_from_lib.bash is executed, has this data:
$BASH_SOURCE[1] == ../lib.bash$PWD == $HOME
To manage breakpoints, we have to resolve ../lib.bash to its source file.
But atm we're only attempting to guess its directory by looking into directories${_Dbg_init_cwd}, $_Dbg_cdir and $(pwd).
But files can be sourced from any directory, based on the working directory at the time source is called.
To reliably find the source file of ../lib.bash we need to know the working directory when source ../lib.bash is called, i.e. we need to know that it's /path/to/some-dir.
With debug output added to the TRAP handler, this is what's available when cd some-dir and . ../lib.bash is called:
TRAP: commmand='cd 'some-dir'', PWD=/Work/source/bashdb/tmp/sources, BASH_SOURCE=../lib/hook.sh sources/main.bash ../bashdb
TRAP: commmand='. ../lib.bash', PWD=/Work/source/bashdb/tmp/sources/some-dir, BASH_SOURCE=../lib/hook.sh sources/main.bash ../bashdb
Possible approach: In the trap handler, it may work to detect . and source commands in $_Dbg_bash_command and store the absolute path of ../lib.bash based on the current $PWD. This would involve parsing the bash command and there won't be a complete solution handling all edge-cases. But managing the basic source ./file/path ignored-args... should be possible, I think.
I'm not an expert with trap handlers and it's possible that I'm not aware of other, possible solutions.
@rocky Do you think that this may work? Do you perhaps know a better approach to solve this?
- Dominant language
- Shell
- Stars
- 98
- Forks
- 13
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Trepan-Debuggers/bashdb
-
Difficulty 3/5 1-2 days Newbie friendliness 55/100
Trepan-Debuggers/bashdb#71 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
Trepan-Debuggers/bashdb#32 · 1 comment ·
All issues in Trepan-Debuggers/bashdb
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
danielmiessler/LifeOS#2218 ·
-
docs(agents): strengthen the no-backslash-escaped-backticks rule with an issue-creation example Open
Difficulty 1/5 Under an hour Newbie friendliness 92/100
-
technical-debt
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
ll7/robot_sf_ll7#9560 ·
-
package-update
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
oSoWoSo/vOid_Community_repOsitory#148 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100