Skip to content
rocky edited this page Mar 3, 2016 · 9 revisions

Here we list some of the cooler commands that you might not be familiar with.

See also:

Auto Evaluation

The debugger has a mode where anything you type into the debugger that recognized as a debugger command is automatically evaluated as zsh code. The way the debugger determines if something is a debugger command is by looking up the first blank-delimited token in a command table and failing to find anything there, in an alias table. Aliases are customizable. (See the help for alias and unalias.) Commands are not once they are added.

When this mode is set, if what you type is erroneous the corresponding zsh error message is displayed and this sometime might be confusing if what you thought you typed was a debugger command rather than a zsh command.

$ zshdb /etc/init.d/apparmor status
Copyright 2008, 2009, 2010, 2011 Rocky Bernstein
This is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.

(/etc/init.d/apparmor:35):
. /etc/apparmor/functions
zshdb<1> lis 5
** Undefined command "lis". Try "help".
zshdb<1> set autoeval on
Evaluate unrecognized commands is on.
zshdb<2> lis 5
/tmp/zshdb_eval_1713:2: command not found: lis
$? is 127
zshdb<3> list 5
  1:    #!/bin/sh
  2:    # ----------------------------------------------------------------------
  3:    #    Copyright (c) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
  4:    #     NOVELL (All rights reserved)
  5:    #    Copyright (c) 2008, 2009 Canonical, Ltd.
  6:    #
  7:    #    This program is free software; you can redistribute it and/or
  8:    #    modify it under the terms of version 2 of the GNU General Public
  9:    #    License published by the Free Software Foundation.
 10:    #
zshdb<4> 

Because of the above potential confusion and because entering commands to be evaluated can be destructive, this mode is turned off by default. However most non-novice users prefer to set this mode on.

Auto list

Normally only the source code line to be displayed is listed in stopping in the debugger. However it is possible to automatically list more context automatically on each stop. For this use set autolist.

Here is a sample session:

$ zshdb hanoi.sh 
zshdb hanoi.sh 
zsh debugger, zshdb, release 0.07

Copyright 2008, 2009, 2010, 2011 Rocky Bernstein
This is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.

(/hanoi.sh:6):
init () { if (( $tracing )) then _Dbg_set_linetrace=1 fi }
zshdb<1> set autolist on
Auto run of 'list' command is on.
zshdb<2> s
(/hanoi.sh:13):
hanoi () {
	typeset -i n=$1
	typeset -r a=$2
	typeset -r b=$3
	typeset -r c ...
  8:      if (( $tracing )) ; then
  9:        _Dbg_set_linetrace=1
 10:      fi
 11:    }
 12:    
 13: => hanoi() { 
 14:      typeset -i n=$1
 15:      # _Dbg_set_trace
 16:      typeset -r a=$2
 17:      typeset -r b=$3
zshdb<3> s
(/hanoi.sh:30):
typeset -i max=3
 25:           hanoi $n $c $b $a
 26:        fi
 27:      fi
 28:    }
 29:    
 30: => typeset -i max=3
 31:    typeset -i tracing=0
 32:    if [[ "$1" = 'trace' ]] ; then
 33:      if [[ -n $2 ]] ; then
 34:          abs_top_builddir=$2
zshdb<4> s
(/hanoi.sh:31):
typeset -i tracing=0
 26:        fi
 27:      fi
 28:    }
 29:    
 30:    typeset -i max=3
 31: => typeset -i tracing=0
 32:    if [[ "$1" = 'trace' ]] ; then
 33:      if [[ -n $2 ]] ; then
 34:          abs_top_builddir=$2
 35:      elif [[ -z $builddir ]] ; then

If you want to change the number of context lines use set listsize:

zshdb<5> set listsize 4
zshdb<6> step
(/hanoi.sh:32):
if [[ "$1" = 'trace' ]]
then
	if [[ -n $2 ]]
	then
		abs_top_builddir=$2 
	 ...
 30:    typeset -i max=3
 31:    typeset -i tracing=0
 32: => if [[ "$1" = 'trace' ]] ; then
 33:      if [[ -n $2 ]] ; then
zshdb<7> step
(/hanoi.sh:32):
[[ "$1" = 'trace' ]]
 30:    typeset -i max=3
 31:    typeset -i tracing=0
 32: => if [[ "$1" = 'trace' ]] ; then
 33:      if [[ -n $2 ]] ; then
zshdb<9> 

To be continued...

Clone this wiki locally