Menu

[0c50c7]: / lib / processor.sh  Maximize  Restore  History

Download this file

473 lines (398 with data), 15.3 kB

  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
# -*- shell-script -*-
# dbg-processor.sh - Top-level debugger commands
#
# Copyright (C) 2008-2012, 2015
# Rocky Bernstein <rocky@gnu.org>
#
# This program 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.
#
# This program 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 this program; see the file COPYING. If not, write to
# the Free Software Foundation, 59 Temple Place, Suite 330, Boston,
# MA 02111 USA.
# Are we inside the middle of a "skip" command?
typeset -i _Dbg_inside_skip=0
# Hooks that get run on each command loop
typeset -A _Dbg_cmdloop_hooks
_Dbg_cmdloop_hooks['display']='_Dbg_eval_all_display'
# Can be bash's "read" builtin or a command-completing "read" builtin
# provided by this debugger.
typeset _Dbg_read_fn; _Dbg_read_fn='read'
# A variable holding a space is set so it can be used in a "set prompt" command
# ("read" in the main command loop will remove a trailing space so we need
# another way to allow a user to enter spaces in the prompt.)
typeset _Dbg_space=' '
# Should we allow editing of debugger commands?
# The value should either be '-e' or ''. And if it is
# on, the edit style indicates what style edit keystrokes.
typeset _Dbg_edit='-e'
typeset _Dbg_edit_style='emacs' # or vi
set -o $_Dbg_edit_style
# What do we use for a debugger prompt? Technically we don't need to
# use the above $bashdb_space in the assignment below, but we put it
# in to suggest to a user that this is how one gets a spaces into the
# prompt.
typeset _Dbg_prompt_str='$_Dbg_debugger_name${_Dbg_less}${#_Dbg_history[@]}${_Dbg_greater}$_Dbg_space'
# The arguments in the last "x" command.
typeset _Dbg_last_x_args=''
# The canonical name of last command run.
typeset _Dbg_last_cmd=''
# A list of debugger command input-file descriptors.
# Duplicate standard input
typeset -i _Dbg_fdi ; exec {_Dbg_fdi}<&0
typeset -i _Dbg_fd_last=0
# keep a list of source'd command files. If the entry is "" then we are
# interactive.
typeset -a _Dbg_cmdfile; _Dbg_cmdfile=('')
# A list of debugger command input-file descriptors.
typeset -a _Dbg_fd; _Dbg_fd=($_Dbg_fdi)
typeset _Dbg_prompt_output
# ===================== FUNCTIONS =======================================
# The main debugger command reading loop.
#
# Note: We have to be careful here in naming "local" variables. In contrast
# to other places in the debugger, because of the read/eval loop, they are
# in fact seen by those using the debugger. So in contrast to other "local"s
# in the debugger, we prefer to preface these with _Dbg_.
function _Dbg_process_commands {
# initial debugger input source from bashdb arguments
if [[ ! -z "$_Dbg_tty_in" ]] && [[ -r "$_Dbg_tty_in" ]]
then
exec {_Dbg_fdi}<$_Dbg_tty_in
_Dbg_fd[++_Dbg_fd_last]=$_Dbg_fdi
_Dbg_cmdfile+=("$_Dbg_tty_in")
fi
# THIS SHOULD BE DONE IN dbg-sig.sh, but there's a bug in BASH in
# trying to change "trap RETURN" inside a "trap RETURN" handler....
# Turn off return trapping. Not strictly necessary, since it *should* be
# covered by the _Dbg_ test below if we've named functions correctly.
# However turning off the RETURN trap should reduce unnecessary
# trap RETURN calls.
_Dbg_inside_skip=0
_Dbg_step_ignore=-1 # Nuke any prior step ignore counts
_Dbg_continue_rc=-1 # Don't continue exectuion unless told to do so.
_Dbg_write_journal "_Dbg_step_ignore=$_Dbg_step_ignore"
typeset key
# Evaluate all hooks
for key in ${!_Dbg_cmdloop_hooks[@]} ; do
${_Dbg_cmdloop_hooks[$key]}
done
# Loop over all pending open input file descriptors
while (( _Dbg_fd_last > 0)) ; do
# Set up prompt to show shell and subshell levels.
typeset _Dbg_greater=''
typeset _Dbg_less=''
typeset _Dbg_result # Used by _Dbg_copies to return a value.
if _Dbg_copies '>' $_Dbg_DEBUGGER_LEVEL ; then
_Dbg_greater=$_Dbg_result
_Dbg_less=${_Dbg_result//>/<}
fi
if _Dbg_copies ')' $BASH_SUBSHELL ; then
_Dbg_greater="${_Dbg_result}${_Dbg_greater}"
_Dbg_less="${_Dbg_less}${_Dbg_result//)/(}"
fi
# Loop over debugger commands. But before reading a debugger
# command, we need to make sure IFS is set to spaces to ensure our
# two variables (command name and rest of the arguments) are set
# correctly. Saving the IFS and setting it to the "normal" value
# of space should be done in the DEBUG signal handler entry.
# Also, we need to make sure the prompt output is
# redirected to the debugger terminal. Both of these things may
# have been changed by the debugged program for its own
# purposes. Furthermore, were we *not* to redirect our stderr
# below, we may mess up what the debugged program expects to see
# in in stderr by adding our debugger prompt.
# if no tty, no prompt
_Dbg_prompt_output=${_Dbg_tty:-/dev/null}
eval "local _Dbg_prompt=$_Dbg_prompt_str"
_Dbg_preloop
typeset _Dbg_cmd
typeset args
typeset rc
while : ; do
set -o history
_Dbg_input_desc=${_Dbg_fd[_Dbg_fd_last]}
if [[ $_Dbg_tty == '&1' ]] ; then
echo -n "$_Dbg_prompt"
if ! read _Dbg_cmd args <&$_Dbg_input_desc 2>&1; then
break
fi
else
if ((_Dbg_set_read_completion)) ; then
_Dbg_read_fn='readc'
else
_Dbg_read_fn='read'
fi
if ! $_Dbg_read_fn $_Dbg_edit -p "$_Dbg_prompt" _Dbg_cmd args \
<&$_Dbg_input_desc 2>>$_Dbg_prompt_output ; then
set +o history
break
fi
fi
# FIXME: until I figure out to fix builtin readc, this happens
# on command completion:
if [[ $_Dbg_cmd =~ ' ' && -z $args ]] ; then
typeset -a ary; IFS=' ' ary=( $_Dbg_cmd )
_Dbg_cmd=${ary[0]}
unset ary[0]
args="${ary[@]}"
fi
set +o history
if (( _Dbg_brkpt_commands_defining )) ; then
case $_Dbg_cmd in
silent )
_Dbg_brkpt_commands_silent[$_Dbg_brkpt_commands_current]=1
continue
;;
end )
_Dbg_brkpt_commands_defining=0
#### ??? TESTING
## local -i cur=$_Dbg_brkpt_commands_current
## local -i start=${_Dbg_brkpt_commands_start[$cur]}
## local -i end=${_Dbg_brkpt_commands_end[$cur]}
## local -i i
## echo "++ brkpt: $cur, start: $start, end: $end "
## for (( i=start; (( i < end )) ; i++ )) ; do
## echo ${_Dbg_brkpt_commands[$i]}
## done
eval "_Dbg_prompt=$_Dbg_prompt_str"
continue
;;
*)
_Dbg_brkpt_commands[${#_Dbg_brkpt_commands[@]}]="$_Dbg_cmd $args"
(( _Dbg_brkpt_commands_end[$_Dbg_brkpt_commands_current]++ ))
continue
;;
esac
rc=$?
else
_Dbg_onecmd "$_Dbg_cmd" "$args"
_Dbg_postcmd
fi
((_Dbg_continue_rc >= 0)) && return $_Dbg_continue_rc
if (( _Dbg_brkpt_commands_defining )) ; then
_Dbg_prompt='>'
else
eval "_Dbg_prompt=$_Dbg_prompt_str"
fi
done # while read $_Dbg_edit -p ...
unset _Dbg_fd[_Dbg_fd_last--]
done # Loop over all open pending file descriptors
# EOF hit. Same as quit without arguments
_Dbg_msg '' # Cause <cr> since EOF may not have put in.
_Dbg_do_quit
}
# Run a debugger command "annotating" the output
_Dbg_annotation() {
typeset label="$1"
shift
_Dbg_do_print "$label"
$*
_Dbg_do_print ''
}
# Run a single command
# Parameters: _Dbg_cmd and args
#
_Dbg_onecmd() {
typeset full_cmd=$@
typeset _Dbg_orig_cmd="$1"
typeset expanded_alias; _Dbg_alias_expand "$_Dbg_orig_cmd"
typeset _Dbg_cmd="$expanded_alias"
shift
typeset _Dbg_args="$@"
# Set default next, step or skip command
if [[ -z $_Dbg_cmd ]]; then
_Dbg_cmd=$_Dbg_last_next_step_cmd
_Dbg_args=$_Dbg_last_next_step_args
full_cmd="$_Dbg_cmd $_Dbg_args"
fi
# If "set trace-commands" is "on", echo the the command
if [[ $_Dbg_set_trace_commands == 'on' ]] ; then
_Dbg_msg "+$full_cmd"
fi
local dq_cmd=$(_Dbg_esc_dq "$_Dbg_cmd")
local dq_args=$(_Dbg_esc_dq "$_Dbg_args")
# _Dbg_write_journal_eval doesn't work here. Don't really understand
# how to get it to work. So we do this in two steps.
_Dbg_write_journal \
"_Dbg_history[${#_Dbg_history[@]}]=\"$dq_cmd $dq_args\""
_Dbg_history[${#_Dbg_history[@]}]="$_Dbg_cmd $_Dbg_args"
_Dbg_hi=${#_Dbg_history[@]}
history -s -- "$full_cmd"
typeset -i _Dbg_redo=1
while (( _Dbg_redo )) ; do
_Dbg_redo=0
[[ -z $_Dbg_cmd ]] && _Dbg_cmd=$_Dbg_last_cmd
if [[ -n $_Dbg_cmd ]] ; then
typeset -i found=0
typeset found_cmd
if [[ -n ${_Dbg_debugger_commands[$_Dbg_cmd]} ]] ; then
found=1
found_cmd=$_Dbg_cmd
else
# Look for a unique abbreviation
typeset -i count=0
typeset list; list="${!_Dbg_debugger_commands[@]}"
for try in $list ; do
if [[ $try =~ ^$_Dbg_cmd ]] ; then
found_cmd=$try
((count++))
fi
done
((found=(count==1)))
fi
if ((found)); then
${_Dbg_debugger_commands[$found_cmd]} $_Dbg_args
IFS=$_Dbg_space_IFS;
eval "_Dbg_prompt=$_Dbg_prompt_str"
((_Dbg_continue_rc >= 0)) && return $_Dbg_continue_rc
continue
fi
fi
case $_Dbg_cmd in
# Comment line
[#]* )
_Dbg_history_remove_item
_Dbg_last_cmd='#'
;;
# list current line
. )
_Dbg_list $_Dbg_frame_last_filename $_Dbg_frame_last_lineno 1
_Dbg_last_cmd='list'
;;
# Search forwards for pattern
/* )
_Dbg_do_search $_Dbg_cmd
_Dbg_last_cmd='search'
;;
# Search backwards for pattern
[?]* )
_Dbg_do_reverse $_Dbg_cmd
_Dbg_last_cmd="reverse"
;;
# Change Directory
cd )
# Allow for tilde expansion. We also allow expansion of
# variables like $HOME which gdb doesn't allow. That's life.
local cd_command="cd $_Dbg_args"
eval $cd_command
_Dbg_do_pwd
_Dbg_last_cmd='cd'
;;
# complete
comp | compl | comple | complet | complete )
_Dbg_do_complete $_Dbg_args
_Dbg_last_cmd='complete'
;;
# Set up a script for debugging into.
debug )
_Dbg_do_debug $_Dbg_args
# Skip over the execute statement which presumably we ran above.
_Dbg_do_next_skip 'skip' 1
IFS="$_Dbg_old_IFS";
return 1
_Dbg_last_cmd='debug'
;;
# Delete all breakpoints.
D | deletea | deleteal | deleteall )
_Dbg_clear_all_brkpt
_Dbg_last_cmd='deleteall'
;;
# return from function/source without finishing executions
return )
;;
# run shell command. Has to come before ! below.
shell | '!!' )
eval $_Dbg_args ;;
# Send signal to process
si | sig | sign | signa | signal )
_Dbg_do_signal $_Dbg_args
_Dbg_last_cmd='signal'
;;
# single-step
'step+' | 'step-' )
_Dbg_do_step "$_Dbg_cmd" $_Dbg_args
return 0
;;
# # toggle execution trace
# to | tog | togg | toggl | toggle )
# _Dbg_do_trace
# ;;
# List all breakpoints and actions.
L )
_Dbg_do_list_brkpt
_Dbg_list_watch
_Dbg_list_action
;;
# Remove all actions
A )
_Dbg_do_clear_all_actions $_Dbg_args
;;
# List debugger command history
H )
_Dbg_history_remove_item
_Dbg_do_history_list $_Dbg_args
;;
# S List subroutine names
S )
_Dbg_do_list_functions $_Dbg_args
;;
# Dump variables
V )
_Dbg_do_info_variables "$_Dbg_args"
;;
# Has to come after !! of "shell" listed above
# Run an item from the command history
\!* | history )
_Dbg_do_history $_Dbg_args
;;
'' )
# Redo last_cmd
if [[ -n $_Dbg_last_cmd ]] ; then
_Dbg_cmd=$_Dbg_last_cmd
_Dbg_redo=1
fi
;;
* )
if (( _Dbg_set_autoeval )) ; then
_Dbg_do_eval $_Dbg_cmd $_Dbg_args
else
_Dbg_undefined_cmd "$_Dbg_cmd"
_Dbg_history_remove_item
# local -a last_history=(`history 1`)
# history -d ${last_history[0]}
fi
;;
esac
done # while (( $_Dbg_redo ))
IFS=$_Dbg_space_IFS;
eval "_Dbg_prompt=$_Dbg_prompt_str"
}
_Dbg_preloop() {
if ((_Dbg_set_annotate)) ; then
_Dbg_annotation 'breakpoints' _Dbg_do_info breakpoints
# _Dbg_annotation 'locals' _Dbg_do_backtrace 3
_Dbg_annotation 'stack' _Dbg_do_backtrace 3
fi
}
_Dbg_postcmd() {
if ((_Dbg_set_annotate)) ; then
case $_Dbg_last_cmd in
break | tbreak | disable | enable | condition | clear | delete )
_Dbg_annotation 'breakpoints' _Dbg_do_info breakpoints
;;
up | down | frame )
_Dbg_annotation 'stack' _Dbg_do_backtrace 3
;;
* )
esac
fi
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.