Useful Functions in a .dbxrc File

Related Topics:

Useful Aliases in a .dbxrc File Typical Entries in a .dbxrc File

The following useful functions are included when you create a .dbxrc file as described in Creating a .dbxrc File. Uncomment the functions you wish to enable.

function hex    			# print arg in hex
{
: ${1?"usage: $0 <expr> # print <expr> in hex"}
typeset -i16 x
((x = $[(int)$*]))
echo - $* = $x
 }
typeset -q hex

  

function pp 			# print pointer; print expression as 
symbolic
{ # address and hex value
: ${1?"usage: $0 <expr> # print expr as symbolic address and hex
value"}
     builtin examine $[(int)$*]/X
}
typeset -q pp

  

function offsetof  			# print offset of $2 in type $1: offsetof 
strct fld
{
   : ${2?"usage: $0 <structname> <fieldname> # offset of fld in struct"}
   [ -z "$3" ] || { echo "$0: unexpected argument" >&2 && return; }
   echo - $[(int)(&((($1*)0)->$2))]
}
alias off=offsetof

  

function environment			# dump the environment variables of the 
target process
{
   [ -z "$1" ] || { echo "$0: unexpected argument" >&2 && return; }
   typeset -i i=0
   typeset env="((char **)$[(char**)environ])"
   while :
   do
     x=$[($env)[$i]]
     echo "$i: " "${x#0x*\ }"
     case "$x" in
      *\(nil\)*) break;;
     esac
     ((i += 1))
   done
}

  

function hexdump			# dump $2 (default: sizeof $1) bytes in hex
{
    : ${1?"usage: $0 <exp> [<size>] # dump <size> bytes in hex"}
    typeset -i16 p="$[(void *)&$1]" # address of $1
    typeset -i s="${2:-$[sizeof ($1)]}" >/dev/null 2>&1 # number of bytes
builtin examine $p/$[(${s:-4}+3)/4]X
 }
typeset -q hexdump

  

alias hd=hexdump

  

button literal hexdump			# uncomment to install button in the Custom 
Buttons window

  

if $havegui
then
# can't use reverse video in GUI
  RMSO=
else
  SMSO=$(tput smso) # start standout mode (reverse video)
  RMSO=$(tput rmso) # end standout mode
PS1="$SMSO(dbx !)$RMSO "		# reverse-video prompt with history number

  

Example of the _cb_prompt callback routine (see Callbacks)

function _cb_prompt
{
   if $mtfeatures
   then # set prompt for MT debugging
          PS1='${SMSO}${thread} ${lwp} <!>${RMSO} '
   else # set prompt for non-thread debugging
          PS1='${SMSO}dbx<!>${RMSO} '
   fi
}