-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add contrib script to start cgreen under gdb and stop at a particular…
… test
- Loading branch information
Showing
1 changed file
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |