File: break.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 (112 lines) | stat: -rw-r--r-- 3,219 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# -*- shell-script -*-
#   Copyright (C) 2008, 2009 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.

_Dbg_help_add break \
'break [LOCSPEC] -- Set a breakpoint at LOCSPEC. 

If no location specification is given, use the current line.

Multiple breakpoints at one place are permitted, and useful if conditional.
See also "tbreak" and "continue".'

_Dbg_help_add tbreak \
'tbreak [LOCSPEC] -- Set a one-time breakpoint at LOCSPEC. 

Like "break" except the breakpoint is only temporary,
so it will be deleted when hit.  Equivalent to "break" followed
by using "delete" on the breakpoint number.

If no location specification is given, use the current line.'

# Add breakpoint(s) at given line number of the current file.  $1 is
# the line number or _curline if omitted.  $2 is a condition to test
# for whether to stop.
_Dbg_do_break() {

  typeset -i is_temp=$1
  (( $# > 0 )) && shift

  typeset linespec
  if (( $# > 0 )) ; then 
      linespec="$1"
  else
      _Dbg_frame_lineno; linespec=$_Dbg_frame_lineno
  fi
  (( $# > 0 )) && shift

  typeset condition=${1:-''}
  if [[ "$linespec" == 'if' ]]; then
    _Dbg_frame_lineno; linespec=$_Dbg_frame_lineno
  elif [[ -z $condition ]] ; then
    condition=1
  elif [[ $condition == 'if' ]] ; then
    shift
    condition="$*"
  fi
  [[ -z $condition ]] && condition=1

  typeset filename
  typeset -i line_number
  typeset full_filename

  _Dbg_linespec_setup "$linespec"

  if [[ -n "$full_filename" ]]  ; then 
    if (( line_number ==  0 )) ; then 
      _Dbg_errmsg 'There is no line 0 to break at.'
    else 
      _Dbg_check_line $line_number "$full_filename"
      (( $? == 0 )) && \
	_Dbg_set_brkpt "$full_filename" "$line_number" $is_temp "$condition"
    fi
  else
    _Dbg_file_not_read_in "$filename"
  fi
}

# delete brkpt(s) at given file:line numbers. If no file is given
# use the current file.
_Dbg_do_clear_brkpt() {
  typeset -r n=${1:-$_curline}

  typeset filename
  typeset -i line_number
  typeset full_filename

  _Dbg_linespec_setup $n

  if [[ -n $full_filename ]] ; then 
    if (( $line_number ==  0 )) ; then 
      _Dbg_msg "There is no line 0 to clear."
    else 
      _Dbg_check_line $line_number "$full_filename"
      if (( $? == 0 )) ; then
	_Dbg_unset_brkpt "$full_filename" "$line_number"
	typeset -r found=$?
	if [[ $found != 0 ]] ; then 
	  _Dbg_msg "Removed $found breakpoint(s)."
	else 
	  _Dbg_msg "Didn't find any breakpoints to remove at $n."
	fi
      fi
    fi
  else
    _Dbg_file_not_read_in "$filename"
  fi
}

_Dbg_alias_add b break