From 07d8922223244234483e66c1f9cd3830e7a21195 Mon Sep 17 00:00:00 2001 From: rocky Date: Mon, 8 Jun 2020 09:57:42 -0400 Subject: [PATCH] Add gdb "info functions" --- command/info.sh | 5 ++-- command/info_sub/Makefile.am | 1 + command/info_sub/functions.sh | 44 ++++++++++++++++++++++++++++++++ command/info_sub/variables.sh | 14 +++++----- command/list.sh | 2 +- dbg-opts.sh | 2 +- docs/commands/info.rst | 1 + docs/commands/info/functions.rst | 19 ++++++++++++++ lib/info-help.sh | 9 +++++-- 9 files changed, 84 insertions(+), 13 deletions(-) create mode 100644 command/info_sub/functions.sh create mode 100644 docs/commands/info/functions.rst diff --git a/command/info.sh b/command/info.sh index d466f8db..0b67a5ba 100644 --- a/command/info.sh +++ b/command/info.sh @@ -32,7 +32,7 @@ typeset -A _Dbg_command_help_info _Dbg_help_add info '' # Help routine is elsewhere typeset -a _Dbg_info_subcmds -_Dbg_info_subcmds=( breakpoints display files line program source stack variables ) +_Dbg_info_subcmds=( breakpoints display files "function" "line" program source stack variables ) # Load in "info" subcommands for _Dbg_file in ${_Dbg_libdir}/command/info_sub/*.sh ; do @@ -50,13 +50,14 @@ _Dbg_do_info_internal() { typeset label=$2 # Warranty is omitted below. - typeset subcmds='breakpoints display files line source stack variables' + typeset subcmds='breakpoints display files functions line source stack variables' if [[ -z $info_cmd ]] ; then typeset thing for thing in $subcmds ; do _Dbg_do_info $thing 1 done + set +x return 0 elif [[ -n ${_Dbg_debugger_info_commands[$info_cmd]} ]] ; then ${_Dbg_debugger_info_commands[$info_cmd]} $label "$@" diff --git a/command/info_sub/Makefile.am b/command/info_sub/Makefile.am index f39c399c..b9a56531 100644 --- a/command/info_sub/Makefile.am +++ b/command/info_sub/Makefile.am @@ -4,6 +4,7 @@ pkgdatadir = ${datadir}/@PACKAGE@/command/info_sub pkgdata_DATA = \ breakpoints.sh \ files.sh \ + functions.sh \ program.sh \ variables.sh \ warranty.sh diff --git a/command/info_sub/functions.sh b/command/info_sub/functions.sh new file mode 100644 index 00000000..8d8d6eca --- /dev/null +++ b/command/info_sub/functions.sh @@ -0,0 +1,44 @@ +# -*- shell-script -*- +# "info functions" debugger command +# +# Copyright (C) 2020 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_sub info functions ' +**info functions** [*string-pattern*] + +List function names. If *string-pattern* is given, the results +are filtered using the shell "=" (or "==") test. + +Examples: +--------- + + info functions # show all functions + info functions co # show all functions with "co" in the name + +' 1 + +_Dbg_do_info_functions() { + # Remove "functions" or "xx functions" + if [[ "$1" != "functions" ]] ; then + shift + fi + if [[ "$1" == "functions" ]]; then + shift + fi + _Dbg_do_list_typeset_attr '+f' $@ + return 0 +} diff --git a/command/info_sub/variables.sh b/command/info_sub/variables.sh index 06a6c340..a63b6026 100644 --- a/command/info_sub/variables.sh +++ b/command/info_sub/variables.sh @@ -53,15 +53,15 @@ _Dbg_do_info_variables() { return 0 ;; fu|fun|func|funct|functi|functio|function|functions ) - _Dbg_do_list_typeset_attr '+f' $* + _Dbg_do_list_typeset_attr '+f' $@ return 0 ;; fi|fix|fixe|fixed ) - _Dbg_do_list_typeset_attr '+F' $* + _Dbg_do_list_typeset_attr '+F' $@ return 0 ;; fl|flo|floa|float|floats) - _Dbg_do_list_typeset_attr '+E' $* + _Dbg_do_list_typeset_attr '+E' $@ return 0 ;; # g | gl | glo | glob | globa | global ) @@ -69,11 +69,11 @@ _Dbg_do_info_variables() { # return 0 # ;; h | ha | has | hash ) - _Dbg_do_list_typeset_attr '+A' $* + _Dbg_do_list_typeset_attr '+A' $@ return 0 ;; i | in | int| inte | integ | intege | integer | integers ) - _Dbg_do_list_typeset_attr '+i' $* + _Dbg_do_list_typeset_attr '+i' $@ return 0 ;; # l | lo | loc | loca | local | locals ) @@ -81,11 +81,11 @@ _Dbg_do_info_variables() { # return 0 # ;; # p | pr | pro| prop | prope | proper | propert | properti | propertie | properties ) - # _Dbg_do_list_typeset_attr '+p' $* + # _Dbg_do_list_typeset_attr '+p' $@ # return 0 # ;; r | re | rea| read | reado | readon | readonl | readonly ) - _Dbg_do_list_typeset_attr '+r' $* + _Dbg_do_list_typeset_attr '+r' $@ return 0 ;; * ) diff --git a/command/list.sh b/command/list.sh index fcb69559..4023916c 100644 --- a/command/list.sh +++ b/command/list.sh @@ -142,7 +142,7 @@ _Dbg_do_list_typeset_attr() { (($# == 0)) && return 1 typeset attr="$1"; shift typeset -a list - list=( $(_Dbg_get_typeset_attr "$attr" $*) ) + list=( $(_Dbg_get_typeset_attr "$attr" $@) ) typeset -i rc=$? (( rc != 0 )) && return $rc _Dbg_list_columns diff --git a/dbg-opts.sh b/dbg-opts.sh index 0b5be024..f4edccc6 100644 --- a/dbg-opts.sh +++ b/dbg-opts.sh @@ -236,7 +236,7 @@ _Dbg_parse_options() { [[ -n $_Dbg_release ]] ; then echo "$_Dbg_shell_name debugger, $_Dbg_debugger_name, release $_Dbg_release" printf ' -Copyright 2008-2011, 2014, 2016-2019 Rocky Bernstein +Copyright 2008-2011, 2014, 2016-2020 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. diff --git a/docs/commands/info.rst b/docs/commands/info.rst index fd974f5e..bfe65fa4 100644 --- a/docs/commands/info.rst +++ b/docs/commands/info.rst @@ -16,6 +16,7 @@ Type `info` for a list of info subcommands and what they do. Type ``help info`` info/breakpoints info/display info/files + info/functions info/line info/program info/source diff --git a/docs/commands/info/functions.rst b/docs/commands/info/functions.rst new file mode 100644 index 00000000..196d678c --- /dev/null +++ b/docs/commands/info/functions.rst @@ -0,0 +1,19 @@ +.. index:: info; functions +.. _info_functions: + +Info Variables +---------------- + +**info functions** [*string-pattern*] + +List function names. If *string-pattern* is given, the results +are filtered using the shell `=` (or `==`) test. +list global and static variable names. + +Examples: ++++++++++ + +:: + + info functions # show all functions + info functions co # show all functions with "co" in the name diff --git a/lib/info-help.sh b/lib/info-help.sh index aa5df48d..15c57927 100644 --- a/lib/info-help.sh +++ b/lib/info-help.sh @@ -17,7 +17,7 @@ # with zshdb; see the file COPYING. If not, write to the Free Software # Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. -typeset -r _Dbg_info_cmds='breakpoints display files line program source stack variables warranty' +typeset -r _Dbg_info_cmds='breakpoints display files functions line program source stack variables warranty' _Dbg_info_help() { @@ -68,9 +68,14 @@ _Dbg_info_help() { 'info files -- Source files in the program' return 0 ;; + 'fu' | fun | func | funct | functi | functio | 'function' | functions ) + _Dbg_msg \ + 'info functions -- Functions defined in the program' + return 0 + ;; l | li| lin | line ) _Dbg_msg \ - 'info line -- list current line number and and file name' + 'info line -- List current line number and and file name' return 0 ;; p | pr | pro | prog | progr | progra | program )