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 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050
|
# dbg-brk.inc - Bourne Again Shell Debugger Break/Watch/Action routines
# Copyright (C) 2002, 2003, 2006, 2007 Rocky Bernstein
# rockyb@users.sourceforge.net
#
# Bash 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.
#
# Bash 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 Bash; see the file COPYING. If not, write to the Free Software
# Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
#================ VARIABLE INITIALIZATIONS ====================#
declare -r _Dbg_brk_ver=\
'$Id: dbg-brk.inc,v 1.15 2007/03/02 07:56:34 rockyb Exp $'
typeset -ar _Dbg_yn=("n" "y")
typeset -ar _Dbg_keep=('keep' 'del')
# action data structures
typeset -ai _Dbg_action_line=() # Line number of breakpoint
typeset -a _Dbg_action_file=() # filename of breakpoint
typeset -ai _Dbg_action_enable=() # 1/0 if enabled or not
typeset -a _Dbg_action_stmt=() # Statement to eval when line is hit.
typeset -i _Dbg_action_max=0 # Needed because we can't figure
# out what the max index is and arrays
# can be sparse
# Note: we loop over possibly sparse arrays with _Dbg_brkpt_max by adding one
# and testing for an entry. Could add yet another array to list only
# used indices. Bash is kind of primitive.
# Breakpoint data structures
typeset -ai _Dbg_brkpt_line=() # Line number of breakpoint
typeset -a _Dbg_brkpt_file=() # filename of breakpoint
typeset -a _Dbg_brkpt_enable=() # 1/0 if enabled or not
typeset -ai _Dbg_brkpt_count=() # Number of times hit
typeset -ai _Dbg_brkpt_onetime=() # Is this a onetime break?
typeset -a _Dbg_brkpt_cond=() # Condition to eval true in order to stop.
typeset -i _Dbg_brkpt_max=0 # Needed because we can't figure out what
# the max index is and arrays can be sparse
# Note: we loop over possibly sparse arrays with _Dbg_brkpt_max by adding one
# and testing for an entry. Could add yet another array to list only
# used indices. Bash is kind of primitive.
# Watchpoint data structures
typeset -a _Dbg_watch_exp=() # Watchpoint expressions
typeset -a _Dbg_watch_val=() # values of watchpoint expressions
typeset -ai _Dbg_watch_arith=() # 1 if arithmetic expression or not.
typeset -ai _Dbg_watch_count=() # Number of times hit
typeset -ai _Dbg_watch_enable=() # 1/0 if enabled or not
typeset -i _Dbg_watch_max=0 # Needed because we can't figure out what
# the max index is and arrays can be sparse
typeset -r _watch_pat="${int_pat}[wW]"
# Display data structures
typeset -a _Dbg_disp_exp=() # Watchpoint expressions
typeset -ai _Dbg_disp_enable=() # 1/0 if enabled or not
typeset -i _Dbg_disp_max=0 # Needed because we can't figure out what
# the max index is and arrays can be sparse
#========================= FUNCTIONS ============================#
# Error message for file not read in
_Dbg_file_not_read_in() {
local -r filename=$(_Dbg_adjust_filename "$1")
_Dbg_msg "File $filename not found in read-in files."
_Dbg_msg "See 'info files' for a list of known files and"
_Dbg_msg "'load' to read in a file."
}
# Common routine for setup of commands that take a single
# linespec argument. We assume the following variables
# which we store into:
# filename, line_number, full_filename
_Dbg_linespec_setup() {
local linespec=${1:-''}
if [[ -z $linespec ]] ; then
_Dbg_msg "Invalid line specification, null given"
fi
local -a word=($(_Dbg_parse_linespec "$linespec"))
if [[ ${#word[@]} == 0 ]] ; then
_Dbg_msg "Invalid line specification: $linespec"
return
fi
filename=${word[2]}
local -ir is_function=${word[1]}
line_number=${word[0]}
full_filename=`_Dbg_is_file $filename`
if (( is_function )) ; then
if [[ -z $full_filename ]] ; then
_Dbg_readin "$filename"
full_filename=`_Dbg_is_file $filename`
fi
fi
}
# Error message for file not read in
_Dbg_file_not_read_in() {
local -r filename=$(_Dbg_adjust_filename ${1:-""})
_Dbg_msg "File $filename not found in read-in files."
_Dbg_msg "See 'info files' for a list of known files and"
_Dbg_msg "'load' to read in a file."
}
_Dbg_save_breakpoints() {
local file
for file in ${_Dbg_filenames[@]} ; do
local filevar="`_Dbg_file2var $file`"
declare -p _Dbg_brkpt_$filevar >> $_Dbg_statefile 2>/dev/null
done
declare -p _Dbg_brkpt_line >> $_Dbg_statefile
declare -p _Dbg_brkpt_file >> $_Dbg_statefile
declare -p _Dbg_brkpt_cond >> $_Dbg_statefile
declare -p _Dbg_brkpt_count >> $_Dbg_statefile
declare -p _Dbg_brkpt_enable >> $_Dbg_statefile
declare -p _Dbg_brkpt_onetime >> $_Dbg_statefile
declare -p _Dbg_brkpt_max >> $_Dbg_statefile
}
_Dbg_save_actions() {
for file in ${_Dbg_filenames[@]} ; do
local filevar="`_Dbg_file2var $file`"
declare -p _Dbg_action_$filevar >> $_Dbg_statefile 2>/dev/null
done
declare -p _Dbg_action_line >> $_Dbg_statefile
declare -p _Dbg_action_file >> $_Dbg_statefile
declare -p _Dbg_action_enable >> $_Dbg_statefile
declare -p _Dbg_action_stmt >> $_Dbg_statefile
declare -p _Dbg_action_max >> $_Dbg_statefile
}
_Dbg_save_watchpoints() {
declare -p _Dbg_watch_exp >> $_Dbg_statefile
declare -p _Dbg_watch_val >> $_Dbg_statefile
declare -p _Dbg_watch_arith >> $_Dbg_statefile
declare -p _Dbg_watch_count >> $_Dbg_statefile
declare -p _Dbg_watch_enable >> $_Dbg_statefile
declare -p _Dbg_watch_max >> $_Dbg_statefile
}
_Dbg_save_display() {
declare -p _Dbg_disp_exp >> $_Dbg_statefile
declare -p _Dbg_disp_enable >> $_Dbg_statefile
declare -p _Dbg_disp_max >> $_Dbg_statefile
}
# Start out with general break/watchpoint functions first...
# Routine to a delete breakpoint/watchpoint by entry numbers.
_Dbg_do_delete() {
local -r to_go=$@
local -i i
local -i found=0
# set -xv
eval "$_seteglob"
for del in $to_go ; do
case $del in
$_watch_pat )
_Dbg_delete_watch_entry ${del:0:${#del}-1}
;;
$int_pat )
_Dbg_delete_brkpt_entry $del
((found += $?))
;;
* )
_Dbg_msg "Invalid entry number skipped: $del"
esac
done
eval "$_resteglob"
[[ $found != 0 ]] && _Dbg_msg "Removed $found breakpoint(s)."
return $found
# set +xv
}
# Enable/disable breakpoint or watchpoint by entry numbers.
_Dbg_enable_disable() {
if [ -z "$1" ] ; then
_Dbg_msg "Expecting a list of breakpoint/watchpoint numbers. Got none."
return 1
fi
local -i on=$1
local en_dis=$2
shift; shift
if [[ $1 = 'display' ]] ; then
shift
local to_go="$@"
local i
eval "$_seteglob"
for i in $to_go ; do
case $i in
$int_pat )
_Dbg_enable_disable_display $on $en_dis $i
;;
* )
_Dbg_msg "Invalid entry number skipped: $i"
esac
done
eval "$_resteglob"
return 0
elif [[ $1 = 'action' ]] ; then
shift
local to_go="$@"
local i
eval "$_seteglob"
for i in $to_go ; do
case $i in
$int_pat )
_Dbg_enable_disable_action $on $en_dis $i
;;
* )
_Dbg_msg "Invalid entry number skipped: $i"
esac
done
eval "$_resteglob"
return 0
fi
local to_go="$@"
local i
eval "$_seteglob"
for i in $to_go ; do
case $i in
$_watch_pat )
_Dbg_enable_disable_watch $on $en_dis ${del:0:${#del}-1}
;;
$int_pat )
_Dbg_enable_disable_brkpt $on $en_dis $i
;;
* )
_Dbg_msg "Invalid entry number skipped: $i"
esac
done
eval "$_resteglob"
return 0
}
_Dbg_do_continue() {
# set -xv
if (( ! _Dbg_running )) ; then
_Dbg_msg "The program is not being run."
return
fi
[[ -z "$1" ]] && return 0
local filename
local -i line_number
local full_filename
_Dbg_linespec_setup $1
if [[ -n $full_filename ]] ; then
if (( $line_number == 0 )) ; then
_Dbg_msg "There is no line 0 to continue at."
else
_Dbg_check_line $line_number "$full_filename"
(( $? == 0 )) && \
_Dbg_set_brkpt "$full_filename" "$line_number" 1 1
return 0
fi
else
_Dbg_file_not_read_in $filename
fi
return 1
}
# Enable breakpoint(s)/watchpoint(s) by entry number(s).
_Dbg_do_enable() {
_Dbg_enable_disable 1 "enabled" $@
}
# Disable breakpoint(s)/watchpoint(s) by entry number(s).
_Dbg_do_disable() {
_Dbg_enable_disable 0 "disabled" $@
}
_Dbg_print_brkpt_count() {
local -ir i=$1
if (( _Dbg_brkpt_count[$i] != 0 )) ; then
if (( _Dbg_brkpt_count[$i] == 1 )) ; then
_Dbg_printf "\tbreakpoint already hit 1 time"
else
_Dbg_printf "\tbreakpoint already hit %d times" ${_Dbg_brkpt_count[$i]}
fi
fi
}
#======================== BREAKPOINTS ============================#
# 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() {
local -i is_temp=$1
shift
local n=${1:-$_curline}
shift
local condition=${1:-''};
if [[ "$n" == 'if' ]]; then
n=$_curline
elif [[ -z $condition ]] ; then
condition=1
elif [[ $condition == 'if' ]] ; then
shift
fi
if [[ -z $condition ]] ; then
condition=1
else
condition="$*"
fi
local filename
local -i line_number
local full_filename
_Dbg_linespec_setup $n
if [[ -n $full_filename ]] ; then
if (( $line_number == 0 )) ; then
_Dbg_msg "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
}
# Set a condition for a given breakpoint $1 is a breakpoint number
# $2 is a condition. If not given, set "unconditional" or 1.
# returns 0 if success or 1 if fail.
_Dbg_do_condition() {
# set -x
local -r n=$1
shift
local condition="$@"
# set -xv
if [[ -z $n ]]; then
_Dbg_msg "Argument required (breakpoint number)."
return 1
fi
eval "$_seteglob"
if [[ $n != $int_pat ]]; then
eval "$_resteglob"
_Dbg_msg "Bad breakpoint number: $n"
return 1
fi
eval "$_resteglob"
if [[ -z ${_Dbg_brkpt_file[$n]} ]] ; then
_Dbg_msg "Breakpoint entry $n is not set. Condition not changed."
return 1
fi
if [[ -z $condition ]] ; then
condition=1
_Dbg_msg "Breakpoint $n now unconditional."
fi
_Dbg_brkpt_cond[$n]="$condition"
return 0
}
# delete brkpt(s) at given file:line numbers. If no file is given
# use the current file.
_Dbg_do_clear_brkpt() {
# set -x
local -r n=${1:-$_curline}
local filename
local -i line_number
local 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"
local -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
}
# list breakpoints and break condition.
# If $1 is given just list those associated for that line.
_Dbg_do_list_brkpt() {
local brkpt_num=${1:-''}
eval "$_seteglob"
if [[ -n $brkpt_num ]] ; then
if [[ $brkpt_num != $int_pat ]]; then
_Dbg_msg "Bad breakpoint number $brkpt_num."
elif [[ -z ${_Dbg_brkpt_file[$brkpt_num]} ]] ; then
_Dbg_msg "Breakpoint entry $brkpt_num is not set."
else
local -r -i i=$brkpt_num
local source_file=${_Dbg_brkpt_file[$i]}
source_file=$(_Dbg_adjust_filename "$source_file")
_Dbg_msg "Num Type Disp Enb What"
_Dbg_printf "%-3d breakpoint %-4s %-3s %s:%s" $i \
${_Dbg_keep[${_Dbg_brkpt_onetime[$i]}]} \
${_Dbg_yn[${_Dbg_brkpt_enable[$i]}]} \
$source_file ${_Dbg_brkpt_line[$i]}
if [[ ${_Dbg_brkpt_cond[$i]} != '1' ]] ; then
_Dbg_printf "\tstop only if %s" "${_Dbg_brkpt_cond[$i]}"
fi
_Dbg_print_brkpt_count ${_Dbg_brkpt_count[$i]}
fi
eval "$_resteglob"
return
fi
if [ ${#_Dbg_brkpt_line[@]} != 0 ]; then
local -i i
_Dbg_msg "Num Type Disp Enb What"
for (( i=1; (( i <= _Dbg_brkpt_max )) ; i++ )) ; do
local source_file=${_Dbg_brkpt_file[$i]}
if [[ -n ${_Dbg_brkpt_line[$i]} ]] ; then
source_file=$(_Dbg_adjust_filename "$source_file")
_Dbg_printf "%-3d breakpoint %-4s %-3s %s:%s" $i \
${_Dbg_keep[${_Dbg_brkpt_onetime[$i]}]} \
${_Dbg_yn[${_Dbg_brkpt_enable[$i]}]} \
$source_file ${_Dbg_brkpt_line[$i]}
if [[ ${_Dbg_brkpt_cond[$i]} != '1' ]] ; then
_Dbg_printf "\tstop only if %s" "${_Dbg_brkpt_cond[$i]}"
fi
if (( _Dbg_brkpt_count[$i] != 0 )) ; then
_Dbg_print_brkpt_count ${_Dbg_brkpt_count[$i]}
fi
fi
done
else
_Dbg_msg "No breakpoints have been set."
fi
}
# clear all brkpts
_Dbg_clear_all_brkpt() {
local -i k
for (( k=0; (( k < ${#_Dbg_filenames[@]} )) ; k++ )) ; do
local filename=${_filename[$k]}
local filevar="`_Dbg_file2var $filename`"
local brkpt_a="_Dbg_brkpt_${filevar}"
_Dbg_write_journal_eval "unset ${brkpt_a}[$k]"
done
_Dbg_write_journal_eval "_Dbg_brkpt_line=()"
_Dbg_write_journal_eval "_Dbg_brkpt_cond=()"
_Dbg_write_journal_eval "_Dbg_brkpt_file=()"
_Dbg_write_journal_eval "_Dbg_brkpt_enable=()"
_Dbg_write_journal_eval "_Dbg_brkpt_count=()"
_Dbg_write_journal_eval "_Dbg_brkpt_onetime=()"
}
# Internal routine to a set breakpoint unconditonally.
_Dbg_set_brkpt() {
local source_file=$1
local -ir line=$2
local -ir is_temp=$3
local -r condition=${4:-1}
local -r filevar="`_Dbg_file2var $source_file`"
local val_str=`_Dbg_get_assoc_array_entry "_Dbg_brkpt_$filevar" $line`
# Increment brkpt_max here because we are 1-origin
((_Dbg_brkpt_max++))
if [ -z "$val_str" ] ; then
val_str=$_Dbg_brkpt_max
else
val_str="$val_str $_Dbg_brkpt_max"
fi
_Dbg_brkpt_line[$_Dbg_brkpt_max]=$line
_Dbg_brkpt_file[$_Dbg_brkpt_max]="$source_file"
_Dbg_brkpt_cond[$_Dbg_brkpt_max]="$condition"
_Dbg_brkpt_onetime[$_Dbg_brkpt_max]=$is_temp
_Dbg_brkpt_count[$_Dbg_brkpt_max]=0
_Dbg_brkpt_enable[$_Dbg_brkpt_max]=1
local dq_source_file=$(_Dbg_esc_dq "$source_file")
local dq_condition=$(_Dbg_esc_dq "$condition")
_Dbg_write_journal "_Dbg_brkpt_line[$_Dbg_brkpt_max]=$line"
_Dbg_write_journal "_Dbg_brkpt_file[$_Dbg_brkpt_max]=\"$dq_source_file\""
_Dbg_write_journal "_Dbg_brkpt_cond[$_Dbg_brkpt_max]=\"$dq_condition\""
_Dbg_write_journal "_Dbg_brkpt_onetime[$_Dbg_brkpt_max]=$is_temp"
_Dbg_write_journal "_Dbg_brkpt_count[$_Dbg_brkpt_max]=\"0\""
_Dbg_write_journal "_Dbg_brkpt_enable[$_Dbg_brkpt_max]=1"
_Dbg_set_assoc_array_entry "_Dbg_brkpt_$filevar" $line $val_str
source_file=$(_Dbg_adjust_filename "$source_file")
if (( $is_temp == 0 )) ; then
_Dbg_msg "Breakpoint $_Dbg_brkpt_max set in file ${source_file}, line $line."
else
_Dbg_msg "One-time breakpoint $_Dbg_brkpt_max set in file ${source_file}, line $line."
fi
_Dbg_write_journal "_Dbg_brkpt_max=$_Dbg_brkpt_max"
}
# Internal routine to unset the actual breakpoint arrays
_Dbg_unset_brkpt_arrays() {
local -i del=$1
_Dbg_write_journal_eval "unset _Dbg_brkpt_line[$del]"
_Dbg_write_journal_eval "unset _Dbg_brkpt_count[$del]"
_Dbg_write_journal_eval "unset _Dbg_brkpt_file[$del]"
_Dbg_write_journal_eval "unset _Dbg_brkpt_enable[$del]"
_Dbg_write_journal_eval "unset _Dbg_brkpt_cond[$del]"
_Dbg_write_journal_eval "unset _Dbg_brkpt_onetime[$del]"
}
# Internal routine to delete a breakpoint by file/line.
_Dbg_unset_brkpt() {
local -r filename=$1
local -ir line=$2
local -r filevar="`_Dbg_file2var $filename`"
local -r fullname="`_Dbg_expand_filename $filename`"
local -i found=0
# set -xv
local -r entries=`_Dbg_get_assoc_array_entry "_Dbg_brkpt_$filevar" $line`
local -i del
for del in $entries ; do
if [[ -z ${_Dbg_brkpt_file[$del]} ]] ; then
_Dbg_msg "No breakpoint found at $filename:$line"
continue
fi
local brkpt_fullname=$(_Dbg_expand_filename ${_Dbg_brkpt_file[$del]})
if [[ $brkpt_fullname != $fullname ]] ; then
_Dbg_msg "Brkpt inconsistency:" \
"$filename[$line] lists ${_Dbg_brkpt_file[$del]} at entry $del"
else
_Dbg_unset_brkpt_arrays $del
((found++))
fi
done
_Dbg_write_journal_eval "unset _Dbg_brkpt_$filevar[$line]"
return $found
# set +xv
}
# Routine to a delete breakpoint by entry number: $1.
# Returns whether or not anything was deleted.
_Dbg_delete_brkpt_entry() {
local -r del=$1
local -i i
local -i found=0
# set -xv
if [[ -z ${_Dbg_brkpt_file[$del]} ]] ; then
_Dbg_msg "Breakpoint entry $del is not set."
return 0
fi
local filevar="`_Dbg_file2var ${_Dbg_brkpt_file[$del]}`"
local line=${_Dbg_brkpt_line[$del]}
local -r entries=`_Dbg_get_assoc_array_entry "_Dbg_brkpt_$filevar" $line`
local try
local -a new_val=()
for try in $entries ; do
if (( $try == $del )) ; then
_Dbg_unset_brkpt_arrays $del
found=1
else
if [[ -n ${_Dbg_brkpt_file[$try]} ]] ; then
new_val[${#new_val[@]}]=$try
fi
fi
done
if [[ ${#new_val[@]} == 0 ]] ; then
_Dbg_write_journal_eval "unset _Dbg_brkpt_$filevar[$line]"
else
_Dbg_set_assoc_array_entry "_Dbg_brkpt_$filevar" $line "${new_val[@]}"
fi
return $found
# set +xv
}
# Enable/disable breakpoint(s) by entry numbers.
_Dbg_enable_disable_brkpt() {
local -i on=$1
local en_dis=$2
local -i i=$3
if [[ -n "${_Dbg_brkpt_file[$i]}" ]] ; then
if [[ ${_Dbg_brkpt_enable[$i]} == $on ]] ; then
_Dbg_msg "Breakpoint entry $i already $en_dis so nothing done."
else
_Dbg_write_journal_eval "_Dbg_brkpt_enable[$i]=$on"
_Dbg_msg "Breakpoint entry $i $en_dis."
fi
else
_Dbg_msg "Breakpoint entry $i doesn't exist so nothing done."
fi
}
#======================== WATCHPOINTS ============================#
_Dbg_get_watch_exp_eval() {
local -i i=$1
local new_val
if [[ `eval echo \"${_Dbg_watch_exp[$i]}\"` == "" ]]; then
new_val=''
elif (( ${_Dbg_watch_arith[$i]} == 1 )) ; then
. ${_Dbg_libdir}/dbg-set-d-vars.inc
eval let new_val=\"${_Dbg_watch_exp[$i]}\"
else
. ${_Dbg_libdir}/dbg-set-d-vars.inc
eval new_val="${_Dbg_watch_exp[$i]}"
fi
echo $new_val
}
# Enable/disable watchpoint(s) by entry numbers.
_Dbg_enable_disable_watch() {
local -i on=$1
local en_dis=$2
local -i i=$3
if [ -n "${_Dbg_watch_exp[$i]}" ] ; then
if [[ ${_Dbg_watch_enable[$i]} == $on ]] ; then
_Dbg_msg "Watchpoint entry $i already $en_dis so nothing done."
else
_Dbg_write_journal_eval "_Dbg_watch_enable[$i]=$on"
_Dbg_msg "Watchpoint entry $i $en_dis."
fi
else
_Dbg_msg "Watchpoint entry $i doesn't exist so nothing done."
fi
}
_Dbg_list_watch() {
if [ ${#_Dbg_watch_exp[@]} != 0 ]; then
local i=0 j
_Dbg_msg "Num Type Enb Expression"
for (( i=0; (( i < _Dbg_watch_max )); i++ )) ; do
if [ -n "${_Dbg_watch_exp[$i]}" ] ;then
_Dbg_printf '%-3d watchpoint %-4s %s' $i \
${_Dbg_yn[${_Dbg_watch_enable[$i]}]} \
"${_Dbg_watch_exp[$i]}"
_Dbg_print_brkpt_count ${_Dbg_watch_count[$i]}
fi
done
else
_Dbg_msg "No watch expressions have been set."
fi
}
_Dbg_delete_watch_entry() {
local -i del=$1
if [ -n "${_Dbg_watch_exp[$del]}" ] ; then
_Dbg_write_journal_eval "unset _Dbg_watch_exp[$del]"
_Dbg_write_journal_eval "unset _Dbg_watch_val[$del]"
_Dbg_write_journal_eval "unset _Dbg_watch_enable[$del]"
_Dbg_write_journal_eval "unset _Dbg_watch_count[$del]"
else
_Dbg_msg "Watchpoint entry $del doesn't exist so nothing done."
fi
}
_Dbg_clear_watch() {
if (( $# < 1 )) ; then
local _Dbg_prompt_output=${_Dbg_tty:-/dev/null}
read $_Dbg_edit -p "Delete all watchpoints? (y/n): " \
<&$_Dbg_input_desc 2>>$_Dbg_prompt_output
if [[ $REPLY = [Yy]* ]] ; then
_Dbg_write_journal_eval unset _Dbg_watch_exp[@]
_Dbg_write_journal_eval unset _Dbg_watch_val[@]
_Dbg_write_journal_eval unset _Dbg_watch_enable[@]
_Dbg_write_journal_eval unset _Dbg_watch_count[@]
_Dbg_msg "All Watchpoints have been cleared"
fi
return 0
fi
eval "$_seteglob"
if [[ $1 == $int_pat ]]; then
_Dbg_write_journal_eval "unset _Dbg_watch_exp[$1]"
_msg "Watchpoint $i has been cleared"
else
_Dbg_list_watch
_basdhb_msg "Please specify a numeric watchpoint number"
fi
eval "$_resteglob"
}
# Set or list watch command
_Dbg_do_watch() {
if [ -z "$2" ]; then
_Dbg_clear_watch
else
local -i n=_Dbg_watch_max++
_Dbg_watch_arith[$n]="$1"
shift
_Dbg_watch_exp[$n]="$1"
_Dbg_watch_val[$n]=`_Dbg_get_watch_exp_eval $n`
_Dbg_watch_enable[$n]=1
_Dbg_watch_count[$n]=0
_Dbg_printf '%2d: %s==%s arith: %d' $n \
"(${_Dbg_watch_exp[$n]})" ${_Dbg_watch_val[$n]} \
${_Dbg_watch_arith[$n]}
fi
}
#======================== ACTIONs ============================#
# Add actions(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_action() {
local n=${1:-$_curline}
shift
local stmt;
if [ -z "$1" ] ; then
condition=1
else
condition="$*"
fi
local filename
local -i line_number
local full_filename
_Dbg_linespec_setup $n
if [[ -n $full_filename ]] ; then
if (( $line_number == 0 )) ; then
_Dbg_msg "There is no line 0 to set action at."
else
_Dbg_check_line $line_number "$full_filename"
(( $? == 0 )) && \
_Dbg_set_action "$full_filename" "$line_number" "$condition"
fi
else
_Dbg_file_not_read_in $filename
fi
}
# clear all actions
_Dbg_do_clear_all_actions() {
local _Dbg_prompt_output=${_Dbg_tty:-/dev/null}
read $_Dbg_edit -p "Delete all actions? (y/n): " \
<&$_Dbg_input_desc 2>>$_Dbg_prompt_output
if [[ $REPLY != [Yy]* ]] ; then
return 1
fi
local -i k
for (( k=0; (( k < ${#_Dbg_filenames[@]} )) ; k++ )) ; do
local filename=${_filename[$k]}
local filevar="`_Dbg_file2var $filename`"
local action_a="_Dbg_action_${filevar}"
unset ${action_a}[$k]
done
_Dbg_write_journal_eval "_Dbg_action_line=()"
_Dbg_write_journal_eval "_Dbg_action_stmt=()"
_Dbg_write_journal_eval "_Dbg_action_file=()"
_Dbg_write_journal_eval "_Dbg_action_enable=()"
return 0
}
# delete actions(s) at given file:line numbers. If no file is given
# use the current file.
_Dbg_do_clear_action() {
# set -x
local -r n=${1:-$_curline}
local filename
local -i line_number
local 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 action at."
else
_Dbg_check_line $line_number "$full_filename"
(( $? == 0 )) && \
_Dbg_unset_action "$full_filename" "$line_number"
local -r found=$?
if [[ $found != 0 ]] ; then
_Dbg_msg "Removed $found action(s)."
else
_Dbg_msg "Didn't find any actions to remove at $n."
fi
fi
else
_Dbg_file_not_read_in $filename
fi
}
# list actions
_Dbg_list_action() {
if [ ${#_Dbg_action_line[@]} != 0 ]; then
_Dbg_msg "Actions at following places:"
local -i i
_Dbg_msg "Num Enb Stmt file:line"
for (( i=0; (( i < _Dbg_action_max )) ; i++ )) ; do
if [[ -n ${_Dbg_action_line[$i]} ]] ; then
local source_file=${_Dbg_action_file[$i]}
source_file=$(_Dbg_adjust_filename "$source_file")
_Dbg_printf "%-3d %3d %-18s %s:%s" $i ${_Dbg_action_enable[$i]} \
"${_Dbg_action_stmt[$i]}" \
$source_file ${_Dbg_action_line[$i]}
fi
done
else
_Dbg_msg "No actions have been set."
fi
}
# Internal routine to a set breakpoint unconditonally.
_Dbg_set_action() {
local source_file=$1
local -ir line=$2
local -r stmt=${3:-1}
local -r filevar="`_Dbg_file2var $source_file`"
local val_str=`_Dbg_get_assoc_array_entry "_Dbg_action_$filevar" $line`
if [ -z "$val_str" ] ; then
val_str=$_Dbg_action_max
else
val_str="$val_str $_Dbg_action_max"
fi
_Dbg_action_line[$_Dbg_action_max]=$line
_Dbg_action_file[$_Dbg_action_max]="$source_file"
_Dbg_action_stmt[$_Dbg_action_max]="$stmt"
_Dbg_action_enable[$_Dbg_action_max]=1
local dq_source_file=$(_Dbg_esc_dq "$source_file")
local dq_stmt=$(_Dbg_esc_dq "stmt")
_Dbg_write_journal "_Dbg_action_line[$_Dbg_action_max]=$line"
_Dbg_write_journal "_Dbg_action_file[$_Dbg_action_max]=\"$dq_source_file\""
_Dbg_write_journal "_Dbg_action_stmt[$_Dbg_action_max]=\"$dq_stmt\""
_Dbg_write_journal "_Dbg_action_enable[$_Dbg_action_max]=1"
_Dbg_set_assoc_array_entry "_Dbg_action_$filevar" $line $val_str
source_file=$(_Dbg_adjust_filename "$source_file")
_Dbg_msg "Breakpoint $_Dbg_action_max set at ${source_file}:$line."
((_Dbg_action_max++))
_Dbg_write_journal "_Dbg_action_max=$_Dbg_action_max"
}
# Internal routine to delete a breakpoint by file/line.
_Dbg_unset_action() {
local -r filename=$1
local -ir line=$2
local -r filevar="`_Dbg_file2var $filename`"
local -i found=0
# set -xv
local -r entries=`_Dbg_get_assoc_array_entry "_Dbg_action_$filevar" $line`
local -i del
for del in $entries ; do
if [[ -z ${_Dbg_action_file[$del]} ]] ; then
_Dbg_msg "No action found at $filename:$line"
continue
fi
if [[ ${_Dbg_action_file[$del]} != $filename ]] ; then
_Dbg_msg "action inconsistency:" \
"$filename[$line] lists ${_Dbg_action_file[$del]} at entry $del"
else
_Dbg_write_journal_eval "unset _Dbg_action_line[$del]"
_Dbg_write_journal_eval "unset _Dbg_action_stmt[$del]"
_Dbg_write_journal_eval "unset _Dbg_action_file[$del]"
_Dbg_write_journal_eval "unset _Dbg_action_enable[$del]"
((found++))
fi
done
_Dbg_write_journal_eval unset _Dbg_action_$filevar[$line]
return $found
# set +xv
}
# Routine to a delete breakpoint/watchpoint by entry numbers.
_Dbg_do_action_delete() {
local -r to_go=$@
local -i i
local -i found=0
# set -xv
eval "$_seteglob"
for del in $to_go ; do
case $del in
$int_pat )
_Dbg_delete_action_entry $del
((found += $?))
;;
* )
_Dbg_msg "Invalid entry number skipped: $del"
esac
done
eval "$_resteglob"
[[ $found != 0 ]] && _Dbg_msg "Removed $found action(s)."
return $found
# set +xv
}
#======================== DISPLAYs ============================#
# Enable/disable display by entry numbers.
_Dbg_disp_enable_disable() {
if [ -z "$1" ] ; then
_Dbg_msg "Expecting a list of display numbers. Got none."
return 1
fi
local -i on=$1
local en_dis=$2
shift; shift
local to_go="$@"
local i
eval "$_seteglob"
for i in $to_go ; do
case $i in
$int_pat )
_Dbg_enable_disable_display $on $en_dis $i
;;
* )
_Dbg_msg "Invalid entry number skipped: $i"
esac
done
eval "$_resteglob"
return 0
}
_Dbg_eval_all_display() {
local -i i
for (( i=0; i < _Dbg_disp_max ; i++ )) ; do
if [ -n "${_Dbg_disp_exp[$i]}" ] \
&& [[ ${_Dbg_disp_enable[i]} != 0 ]] ; then
_Dbg_printf_nocr "%2d (%s): " $i "${_Dbg_disp_exp[i]}"
_Dbg_do_eval "${_Dbg_disp_exp[i]}"
fi
done
}
# Set display command or list all current display expressions
_Dbg_do_display() {
if [[ -z "$@" ]]; then
_Dbg_eval_all_display
else
local -i n=_Dbg_disp_max++
_Dbg_disp_exp[$n]="$@"
_Dbg_disp_enable[$n]=1
_Dbg_printf '%2d: %s' $n "${_Dbg_disp_exp[$n]}"
fi
}
# List display command(s)
_Dbg_do_list_display() {
if [ ${#_Dbg_disp_exp[@]} != 0 ]; then
local i=0 j
_Dbg_msg "Display expressions:"
_Dbg_msg "Num Enb Expression "
for (( i=0; (( i < _Dbg_disp_max )); i++ )) ; do
if [ -n "${_Dbg_disp_exp[$i]}" ] ;then
_Dbg_printf '%-3d %3d %s' \
$i ${_Dbg_disp_enable[$i]} "${_Dbg_disp_exp[$i]}"
fi
done
else
_Dbg_msg "No display expressions have been set."
fi
}
# Enable/disable display(s) by entry numbers.
_Dbg_enable_disable_display() {
local -i on=$1
local en_dis=$2
local -i i=$3
if [ -n "${_Dbg_disp_exp[$i]}" ] ; then
if [[ ${_Dbg_disp_enable[$i]} == $on ]] ; then
_Dbg_msg "Display entry $i already $en_dis so nothing done."
else
_Dbg_write_journal_eval "_Dbg_disp_enable[$i]=$on"
_Dbg_msg "Display entry $i $en_dis."
fi
else
_Dbg_msg "Display entry $i doesn't exist so nothing done."
fi
}
_Dbg_do_undisplay() {
local -i del=$1
if [ -n "${_Dbg_disp_exp[$del]}" ] ; then
_Dbg_write_journal_eval "unset _Dbg_disp_exp[$del]"
_Dbg_write_journal_eval "unset _Dbg_disp_enable[$del]"
else
_Dbg_msg "Display entry $del doesn't exist so nothing done."
fi
}
#;;; Local Variables: ***
#;;; mode:shell-script ***
#;;; eval: (sh-set-shell "bash") ***
#;;; End: ***
|