File: gdb.sh

package info (click to toggle)
zshdb 0.05%2Bgit20101031-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 2,104 kB
  • sloc: sh: 5,563; makefile: 337
file content (82 lines) | stat: -rw-r--r-- 2,639 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# -*- shell-script -*-
# gdb.sh - routines that seem tailored more to the gdb-style of doing things.
#   Copyright (C) 2008 Rocky Bernstein rocky@gnu.org
#
#   zshdb is free software; you can redistribute it and/or modify it under
#   the terms of the GNU General Public License as published by the Free
#   Software Foundation; either version 2, or (at your option) any later
#   version.
#
#   zshdb is distributed in the hope that it will be useful, but WITHOUT ANY
#   WARRANTY; without even the implied warranty of MERCHANTABILITY or
#   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
#   for more details.
#   
#   You should have received a copy of the GNU General Public License along
#   with zshdb; see the file COPYING.  If not, write to the Free Software
#   Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.

# Print location in gdb-style format: file:line
# So happens this is how it's stored in global _Dbg_frame_stack which
# is where we get the information from
function _Dbg_print_location {
    if (($# > 1)); then 
      _Dbg_errmsg "got $# parameters, but need 0 or 1."
      return 2
    fi
    typeset -i pos=${1:-${_Dbg_stack_pos}}
    typeset file_line="${_Dbg_frame_stack[$pos]}"

    typeset split_result; _Dbg_split "$file_line" ':'
    typeset filename="${split_result[0]}"
    typeset -i line="${split_result[1]}"
    if [[ -n $filename ]] ; then 
	_Dbg_readin "${filename}"
	if ((_Dbg_set_basename)); then
	    filename=${filename##*/}
	    file_line="${filename}:${line}"
	fi
	if [[ $filename == $_Dbg_func_stack[1] ]] ; then
	    _Dbg_msg "($file_line): -- nope"
	else
	    _Dbg_msg "($file_line):"
	fi
    fi
}

function _Dbg_print_command {
    typeset -i width; ((width=_Dbg_set_linewidth-6))
    if (( ${#ZSH_DEBUG_CMD} > width )) ; then
	_Dbg_msg "${ZSH_DEBUG_CMD[0,$width]} ..."
    else
	_Dbg_msg $ZSH_DEBUG_CMD
    fi
}

function _Dbg_print_location_and_command {
    _Dbg_print_location $@
    _Dbg_print_command
}

# Print position $1 of stack frame (from global _Dbg_frame_stack)
# Prefix the entry with $2 if that's set.
_Dbg_print_frame() {
    if (($# > 2)); then 
      _Dbg_errmsg "got $# parameters, but need 0 or 1."
      return -1
    fi

    typeset -i pos=${1:-$_Dbg_stack_pos}
    typeset file_line
    file_line="${_Dbg_frame_stack[$pos]}"
    typeset prefix
    prefix=${2:-''}

    typeset -a split_result; _Dbg_split "$file_line" ':'
    typeset filename
    filename="${split_result[0]}"
    typeset -i line="${split_result[1]}"
    (( _Dbg_set_basename )) && filename=${filename##*/}
    _Dbg_msg "$prefix file \`$filename' at line $line"

}