Enable passing arguments to the inferior in debugglibc.sh
diff mbox series

Message ID 20190930150401.GA27942@aloka.lostca.se
State New
Headers show
Series
  • Enable passing arguments to the inferior in debugglibc.sh
Related show

Commit Message

Arjun Shankar Sept. 30, 2019, 3:04 p.m. UTC
This patch adds the ability to run debugglibc.sh's inferior program with
arguments specified on the command line. This enables convenient debugging
of non-testcase programs such as iconv/iconv_prog or other dynamically
linked programs. Program arguments may be passed using `--' as a separator.

For example:

  $ ./debugglibc.sh -b iconv -- iconv/iconv_prog -f ASCII -t UTF-8 input.txt

2019-09-30  Arjun Shankar  <arjun@redhat.com>

	debugglibc.sh: Implement program arguments
	* Makefile (debugglibc): Change variable definition.
--

Discussion Notes:
Initial version: https://sourceware.org/ml/libc-alpha/2019-09/msg00502.html

As per Gabriel's suggestions:
 * Changed the patch to only handle program arguments when `--' is used
 * Documented this in --help (with minor changes: testcase -> program)
Also:
 * It made sense to disable using --direct when program arguments are given

---
 Makefile | 30 ++++++++++++++++++++++--------
 1 file changed, 22 insertions(+), 8 deletions(-)

Comments

Gabriel F. T. Gomes Oct. 1, 2019, 7:56 p.m. UTC | #1
Hi, Arjun,

On Mon, 30 Sep 2019, Arjun Shankar wrote:

>This patch adds the ability to run debugglibc.sh's inferior program with
>arguments specified on the command line. This enables convenient debugging
>of non-testcase programs such as iconv/iconv_prog or other dynamically
>linked programs. Program arguments may be passed using `--' as a separator.

This patch looks good to me.  Thanks.

Reviewed-by: Gabriel F. T. Gomes <gabrielftg@linux.ibm.com>

Patch
diff mbox series

diff --git a/Makefile b/Makefile
index a50fb64dc2..a736c3afcc 100644
--- a/Makefile
+++ b/Makefile
@@ -202,9 +202,12 @@  unset ENVVARS
 usage()
 {
 cat << EOF
-Usage: $$0 [OPTIONS] <testcase>
+Usage: $$0 [OPTIONS] <program>
 
-  where <testcase> is the path to the program being tested.
+   Or: $$0 [OPTIONS] -- <program> [<args>]...
+
+  where <program> is the path to the program being tested,
+  and <args> are the arguments to be passed to it.
 
 Options:
 
@@ -224,11 +227,13 @@  Options:
   The following options do not take arguments:
 
   -i, --no-direct
-	Selects whether to pass the flag --direct to gdb.
-	Required for glibc test cases and not allowed for non-glibc tests.
-	Default behaviour is to pass the flag --direct to gdb.
+	Selects whether to pass the --direct flag to the program.
+	--direct is useful when debugging glibc test cases. It inhibits the
+	tests from forking and executing in a subprocess.
+	Default behaviour is to pass the --direct flag, except when the
+	program is run with user specified arguments using the "--" separator.
   -s, --no-symbols-file
-	Do not tell GDB to load debug symbols from the testcase.
+	Do not tell GDB to load debug symbols from the program.
 EOF
 }
 
@@ -255,8 +260,17 @@  do
     -s|--no-symbols-file)
       SYMBOLSFILE=false
       ;;
+    --)
+      shift
+      TESTCASE=$$1
+      COMMANDLINE="$$@"
+      # Don't add --direct when user specifies program arguments
+      DIRECT=false
+      break
+      ;;
     *)
       TESTCASE=$$1
+      COMMANDLINE=$$TESTCASE
       ;;
   esac
   shift
@@ -302,7 +316,7 @@  __ENVVARS__
 __SYMBOLSFILE__
 break _dl_start_user
 run --library-path $(rpath-link):$${BUILD_DIR}/nptl_db \
-__TESTCASE__ __DIRECT__
+__COMMANDLINE__ __DIRECT__
 __BREAKPOINTS__
 EOF
 }
@@ -311,7 +325,7 @@  EOF
 template | sed \
   -e "s|__ENVVARS__|$$ENVVARSCMD|" \
   -e "s|__SYMBOLSFILE__|$$SYMBOLSFILE|" \
-  -e "s|__TESTCASE__|$$TESTCASE|" \
+  -e "s|__COMMANDLINE__|$$COMMANDLINE|" \
   -e "s|__DIRECT__|$$DIRECT|" \
   -e "s|__BREAKPOINTS__|$$BREAKPOINTS|" \
   > $$CMD_FILE