Skip to content

Commit

Permalink
Add contrib script to start cgreen under gdb and stop at a particular…
Browse files Browse the repository at this point in the history
… test
  • Loading branch information
thoni56 committed May 7, 2018
1 parent 9d026e0 commit faa5f32
Showing 1 changed file with 99 additions and 0 deletions.
99 changes: 99 additions & 0 deletions contrib/cgreen-gdb/cgreen-gdb
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#!/bin/bash
#
# This is a positional arguments-only example of Argbash potential
#
# ARG_HELP([Start cgreen-runner under GDB and break at a specific test])
# ARG_POSITIONAL_SINGLE([library],[Dynamically loadable library with Cgreen tests])
# ARG_POSITIONAL_SINGLE([testname],[The test in Cgreen notation ('<Context>:<test>') to debug])
# ARGBASH_GO()
# needed because of Argbash --> m4_ignore([
### START OF CODE GENERATED BY Argbash v2.6.1 one line above ###
# Argbash is a bash code generator used to get arguments parsing right.
# Argbash is FREE SOFTWARE, see https://argbash.io for more info
# Generated online by https://argbash.io/generate

die()
{
local _ret=$2
test -n "$_ret" || _ret=1
test "$_PRINT_HELP" = yes && print_help >&2
echo "$1" >&2
exit ${_ret}
}

begins_with_short_option()
{
local first_option all_short_options
all_short_options='h'
first_option="${1:0:1}"
test "$all_short_options" = "${all_short_options/$first_option/}" && return 1 || return 0
}



# THE DEFAULTS INITIALIZATION - POSITIONALS
_positionals=()
# THE DEFAULTS INITIALIZATION - OPTIONALS

print_help ()
{
printf '%s\n\n' "Start cgreen-runner under GDB and break at a specific test"
printf 'Usage: %s [-h|--help] <library> <testname>\n\n' "$(basename -- $0)"
printf '\t%s\n' "<library>: Dynamically loadable library with Cgreen tests"
printf '\t%s\n' "<testname>: The test in Cgreen notation ('<Context>:<test>') to debug"
printf '\t%s\n\n' "-h,--help: Prints help"
}

parse_commandline ()
{
while test $# -gt 0
do
_key="$1"
case "$_key" in
-h|--help)
print_help
exit 0
;;
-h*)
print_help
exit 0
;;
*)
_positionals+=("$1")
;;
esac
shift
done
}


handle_passed_args_count ()
{
_required_args_string="'library' and 'testname'"
test ${#_positionals[@]} -ge 2 || _PRINT_HELP=yes die "FATAL ERROR: Not enough positional arguments - we require exactly 2 (namely: $_required_args_string), but got only ${#_positionals[@]}." 1
test ${#_positionals[@]} -le 2 || _PRINT_HELP=yes die "FATAL ERROR: There were spurious positional arguments --- we expect exactly 2 (namely: $_required_args_string), but got ${#_positionals[@]} (the last one was: '${_positionals[*]: -1}')." 1
}

assign_positional_args ()
{
_positional_names=('_arg_library' '_arg_testname' )

for (( ii = 0; ii < ${#_positionals[@]}; ii++))
do
eval "${_positional_names[ii]}=\${_positionals[ii]}" || die "Error during argument parsing, possibly an Argbash bug." 1
done
}

parse_commandline "$@"
handle_passed_args_count
assign_positional_args

# OTHER STUFF GENERATED BY Argbash

### END OF CODE GENERATED BY Argbash (sortof) ### ])
# [ <-- needed because of Argbash

bp=${2//:/__}
echo break $bp > .cgreen-gdb-commands
echo run $1 $2 >> .cgreen-gdb-commands
cgdb -ex "set breakpoint pending on" cgreen-runner --command=.cgreen-gdb-commands

0 comments on commit faa5f32

Please sign in to comment.