Skip to content

Commit

Permalink
Save stack function information
Browse files Browse the repository at this point in the history
  • Loading branch information
rocky committed May 13, 2011
1 parent 6ba69e0 commit 760e843
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion command/where.sh → command/backtrace.sh
Expand Up @@ -21,7 +21,7 @@
# and absolute line positions, not function names and offset.

_Dbg_help_add where \
"where [N] -- Print a backtrace of calling functions and sourced files.
"backtrace [N] -- Print a backtrace of calling functions and sourced files.
The backtrace contains function names, arguments, line numbers, and
files. If N is given, list only N calls."
Expand Down
6 changes: 3 additions & 3 deletions lib/frame.sh
Expand Up @@ -26,7 +26,7 @@ typeset -T Frame_t=(
filename=''
# integer lineno=0
lineno=0
fn=''
fun=''
to_file_line()
{
print -r "file \`${_.filename}' at line ${_.lineno}"
Expand Down Expand Up @@ -135,7 +135,7 @@ _Dbg_frame_save_frames() {
# Frame_t -a ._Dbg_frame_stack gives SEGV
while((--.level>=0)); do
((.sh.level = .level))
.fn+=("${.sh.fun}")
.fun+=("${.sh.fun}")
.files+=("${.sh.file}")
.linenos+=(${.sh.lineno}) # optimization bug unless done this way
.fns+=($0)
Expand All @@ -146,7 +146,7 @@ _Dbg_frame_save_frames() {
for ((_Dbg_i=0; _Dbg_i<.max-start; _Dbg_i++)) ; do
_Dbg_frame_stack[_Dbg_i].filename=${.files[_Dbg_i]}
_Dbg_frame_stack[_Dbg_i].lineno=${.linenos[_Dbg_i]}
_Dbg_frame_stack[_Dbg_i].fn=${.fns[_Dbg_i]}
_Dbg_frame_stack[_Dbg_i].fun=${.fns[_Dbg_i]}
done
for ((_Dbg_i=${#_Dbg_frame_stack[@]}-1; _Dbg_i>=.max-start; _Dbg_i--)); do
unset _Dbg_frame_stack[$_Dbg_i]
Expand Down
10 changes: 8 additions & 2 deletions lib/gdb.sh
Expand Up @@ -29,7 +29,7 @@ function _Dbg_print_location {
typeset -n frame=_Dbg_frame_stack[pos]
typeset filename=${frame.filename}
_Dbg_readin "${filename}"
typeset fn=${frame.fn}
typeset fun=${frame.fun}
((_Dbg_set_basename)) && filename=${filename##*/}
_Dbg_msg "(${filename}:${frame.lineno}):"
}
Expand Down Expand Up @@ -59,5 +59,11 @@ _Dbg_print_frame() {
_Dbg_frame_lineno $pos
typeset -i ln=$?
typeset _Dbg_frame_filename=''; _Dbg_frame_file $pos
_Dbg_msg "$prefix file \`${_Dbg_frame_filename}' at line ${ln}"
typeset loc=''
typeset fun; fun=${_Dbg_frame_stack[pos].fun}
# if [[ -n $fun && \
# $fun != _Dbg_frame_stack[pos].filename ]] ; then
# loc="${_Dbg_frame_stack[pos].fun} from "
# fi
_Dbg_msg "$prefix ${loc}file \`${_Dbg_frame_filename}' at line ${ln}"
}

0 comments on commit 760e843

Please sign in to comment.