libtool-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Enable runtime cwrapper debugging; add tests


From: Charles Wilson
Subject: [PATCH] Enable runtime cwrapper debugging; add tests
Date: Sun, 21 Jun 2009 21:50:42 -0400

* libltdl/config/ltmain.m4sh (func_emit_cwrapperexe_src)
[ltwrapper_debugprintf]: Renamed to...
[lt_debugprintf]: this. Only print messages if lt_debug != 0.
[file scope]: Add constants and variables to support new --lt-debug
option. Remove LTWRAPPER_DEBUGPRINTF macro.
[main]: Consolidate option parsing. Ensure first use of lt_debugprintf
occurs after option parsing. Add stanza to parse for --lt-debug and
set lt_debug variable.
[all]: Use lt_debugprintf () instead of LTWRAPPER_DEBUGPRINTF (()).
* tests/cwrapper.at: Add new tests for --lt-debug and -DLT_DEBUGWRAPPER.
---
Another fragment arising from review of
http://lists.gnu.org/archive/html/libtool-patches/2009-06/msg00031.html

Lightly tested by running "tests/demo-shared.test tests/demo-make.test
tests/demo-exec.test" and cwrapper.at.

Ok to push?


 libltdl/config/ltmain.m4sh |  145 ++++++++++++++++++++++++--------------------
 tests/cwrapper.at          |   52 ++++++++++++++++
 2 files changed, 132 insertions(+), 65 deletions(-)

diff --git a/libltdl/config/ltmain.m4sh b/libltdl/config/ltmain.m4sh
index ebd3909..d8c5749 100644
--- a/libltdl/config/ltmain.m4sh
+++ b/libltdl/config/ltmain.m4sh
@@ -2849,19 +2849,10 @@ int setenv (const char *, const char *, int);
   if (stale) { free ((void *) stale); stale = 0; } \
 } while (0)
 
-#undef LTWRAPPER_DEBUGPRINTF
-#if defined LT_DEBUGWRAPPER
-# define LTWRAPPER_DEBUGPRINTF(args) ltwrapper_debugprintf args
-static void
-ltwrapper_debugprintf (const char *fmt, ...)
-{
-    va_list args;
-    va_start (args, fmt);
-    (void) vfprintf (stderr, fmt, args);
-    va_end (args);
-}
+#if defined(LT_DEBUGWRAPPER)
+static int lt_debug = 1;
 #else
-# define LTWRAPPER_DEBUGPRINTF(args)
+static int lt_debug = 0;
 #endif
 
 const char *program_name = NULL;
@@ -2874,6 +2865,7 @@ char *chase_symlinks (const char *pathspec);
 int make_executable (const char *path);
 int check_executable (const char *path);
 char *strendzap (char *str, const char *pat);
+void lt_debugprintf (const char *fmt, ...);
 void lt_fatal (const char *message, ...);
 void lt_setenv (const char *name, const char *value);
 char *lt_extend_str (const char *orig_value, const char *add, int to_end);
@@ -2881,6 +2873,7 @@ void lt_update_exe_path (const char *name, const char 
*value);
 void lt_update_lib_path (const char *name, const char *value);
 char **prepare_spawn (char **argv);
 void lt_dump_script (FILE *f);
+
 EOF
 
            cat <<EOF
@@ -2932,6 +2925,10 @@ static const size_t opt_prefix_len         = 
LTWRAPPER_OPTION_PREFIX_LENGTH;
 static const char *ltwrapper_option_prefix = LTWRAPPER_OPTION_PREFIX;
 
 static const char *dumpscript_opt       = LTWRAPPER_OPTION_PREFIX 
"dump-script";
+static const size_t dumpscript_opt_len  = LTWRAPPER_OPTION_PREFIX_LENGTH + 11;
+
+static const char *debug_opt            = LTWRAPPER_OPTION_PREFIX "debug";
+static const size_t debug_opt_len       = LTWRAPPER_OPTION_PREFIX_LENGTH + 5;
 
 int
 main (int argc, char *argv[])
@@ -2948,13 +2945,16 @@ main (int argc, char *argv[])
   int i;
 
   program_name = (char *) xstrdup (base_name (argv[0]));
-  LTWRAPPER_DEBUGPRINTF (("(main) argv[0]      : %s\n", argv[0]));
-  LTWRAPPER_DEBUGPRINTF (("(main) program_name : %s\n", program_name));
+  newargz = XMALLOC (char *, argc + 1);
 
-  /* very simple arg parsing; don't want to rely on getopt */
+  /* very simple arg parsing; don't want to rely on getopt
+   * also, copy all non cwrapper options to newargz, except
+   * argz[0], which is handled differently
+   */
+  newargc=0;
   for (i = 1; i < argc; i++)
     {
-      if (strcmp (argv[i], dumpscript_opt) == 0)
+      if (strncmp (argv[i], dumpscript_opt, dumpscript_opt_len) == 0)
        {
 EOF
            case "$host" in
@@ -2968,18 +2968,43 @@ EOF
          lt_dump_script (stdout);
          return 0;
        }
+      if (strncmp (argv[i], debug_opt, debug_opt_len) == 0)
+       {
+          lt_debug = 1;
+          continue;
+       }
+      if (strncmp (argv[i], ltwrapper_option_prefix, opt_prefix_len) == 0)
+        {
+          /* however, if there is an option in the LTWRAPPER_OPTION_PREFIX
+             namespace, but it is not one of the ones we know about and
+             have already dealt with, above (inluding dump-script), then
+             report an error. Otherwise, targets might begin to believe
+             they are allowed to use options in the LTWRAPPER_OPTION_PREFIX
+             namespace. The first time any user complains about this, we'll
+             need to make LTWRAPPER_OPTION_PREFIX a configure-time option
+             or a configure.ac-settable value.
+           */
+          lt_fatal ("Unrecognized option in %s namespace: '%s'",
+                    ltwrapper_option_prefix, argv[i]);
+        }
+      /* otherwise ... */
+      newargz[++newargc] = xstrdup (argv[i]);
     }
+  newargz[++newargc] = NULL;
+
+  /* first use of lt_debugprintf AFTER parsing options */
+  lt_debugprintf ("(main) argv[0]      : %s\n", argv[0]);
+  lt_debugprintf ("(main) program_name : %s\n", program_name);
 
-  newargz = XMALLOC (char *, argc + 1);
   tmp_pathspec = find_executable (argv[0]);
   if (tmp_pathspec == NULL)
     lt_fatal ("Couldn't find %s", argv[0]);
-  LTWRAPPER_DEBUGPRINTF (("(main) found exe (before symlink chase) at : %s\n",
-                         tmp_pathspec));
+  lt_debugprintf ("(main) found exe (before symlink chase) at : %s\n",
+                 tmp_pathspec);
 
   actual_cwrapper_path = chase_symlinks (tmp_pathspec);
-  LTWRAPPER_DEBUGPRINTF (("(main) found exe (after symlink chase) at : %s\n",
-                         actual_cwrapper_path));
+  lt_debugprintf ("(main) found exe (after symlink chase) at : %s\n",
+                 actual_cwrapper_path);
   XFREE (tmp_pathspec);
 
   actual_cwrapper_name = xstrdup( base_name (actual_cwrapper_path));
@@ -3000,8 +3025,8 @@ EOF
   target_name = tmp_pathspec;
   tmp_pathspec = 0;
 
-  LTWRAPPER_DEBUGPRINTF (("(main) libtool target name: %s\n",
-                         target_name));
+  lt_debugprintf ("(main) libtool target name: %s\n",
+                 target_name);
 EOF
 
            cat <<EOF
@@ -3054,32 +3079,10 @@ EOF
   lt_update_lib_path (LIB_PATH_VARNAME, LIB_PATH_VALUE);
   lt_update_exe_path (EXE_PATH_VARNAME, EXE_PATH_VALUE);
 
-  newargc=0;
-  for (i = 1; i < argc; i++)
-    {
-      if (strncmp (argv[i], ltwrapper_option_prefix, opt_prefix_len) == 0)
-        {
-          /* however, if there is an option in the LTWRAPPER_OPTION_PREFIX
-             namespace, but it is not one of the ones we know about and
-             have already dealt with, above (inluding dump-script), then
-             report an error. Otherwise, targets might begin to believe
-             they are allowed to use options in the LTWRAPPER_OPTION_PREFIX
-             namespace. The first time any user complains about this, we'll
-             need to make LTWRAPPER_OPTION_PREFIX a configure-time option
-             or a configure.ac-settable value.
-           */
-          lt_fatal ("Unrecognized option in %s namespace: '%s'",
-                    ltwrapper_option_prefix, argv[i]);
-        }
-      /* otherwise ... */
-      newargz[++newargc] = xstrdup (argv[i]);
-    }
-  newargz[++newargc] = NULL;
-
-  LTWRAPPER_DEBUGPRINTF     (("(main) lt_argv_zero : %s\n", (lt_argv_zero ? 
lt_argv_zero : "<NULL>")));
+  lt_debugprintf     ("(main) lt_argv_zero : %s\n", (lt_argv_zero ? 
lt_argv_zero : "<NULL>"));
   for (i = 0; i < newargc; i++)
     {
-      LTWRAPPER_DEBUGPRINTF (("(main) newargz[%d]   : %s\n", i, (newargz[i] ? 
newargz[i] : "<NULL>")));
+      lt_debugprintf ("(main) newargz[%d]   : %s\n", i, (newargz[i] ? 
newargz[i] : "<NULL>"));
     }
 
 EOF
@@ -3093,7 +3096,7 @@ EOF
   if (rval == -1)
     {
       /* failed to start process */
-      LTWRAPPER_DEBUGPRINTF (("(main) failed to launch target \"%s\": errno = 
%d\n", lt_argv_zero, errno));
+      lt_debugprintf ("(main) failed to launch target \"%s\": errno = %d\n", 
lt_argv_zero, errno);
       return 127;
     }
   return rval;
@@ -3149,8 +3152,8 @@ check_executable (const char *path)
 {
   struct stat st;
 
-  LTWRAPPER_DEBUGPRINTF (("(check_executable)  : %s\n",
-                         path ? (*path ? path : "EMPTY!") : "NULL!"));
+  lt_debugprintf ("(check_executable)  : %s\n",
+                 path ? (*path ? path : "EMPTY!") : "NULL!");
   if ((!path) || (!*path))
     return 0;
 
@@ -3167,8 +3170,8 @@ make_executable (const char *path)
   int rval = 0;
   struct stat st;
 
-  LTWRAPPER_DEBUGPRINTF (("(make_executable)   : %s\n",
-                         path ? (*path ? path : "EMPTY!") : "NULL!"));
+  lt_debugprintf ("(make_executable)   : %s\n",
+                 path ? (*path ? path : "EMPTY!") : "NULL!");
   if ((!path) || (!*path))
     return 0;
 
@@ -3194,8 +3197,8 @@ find_executable (const char *wrapper)
   int tmp_len;
   char *concat_name;
 
-  LTWRAPPER_DEBUGPRINTF (("(find_executable)   : %s\n",
-                         wrapper ? (*wrapper ? wrapper : "EMPTY!") : "NULL!"));
+  lt_debugprintf ("(find_executable)   : %s\n",
+                 wrapper ? (*wrapper ? wrapper : "EMPTY!") : "NULL!");
 
   if ((wrapper == NULL) || (*wrapper == '\0'))
     return NULL;
@@ -3299,8 +3302,8 @@ chase_symlinks (const char *pathspec)
   int has_symlinks = 0;
   while (strlen (tmp_pathspec) && !has_symlinks)
     {
-      LTWRAPPER_DEBUGPRINTF (("checking path component for symlinks: %s\n",
-                             tmp_pathspec));
+      lt_debugprintf ("checking path component for symlinks: %s\n",
+                     tmp_pathspec);
       if (lstat (tmp_pathspec, &s) == 0)
        {
          if (S_ISLNK (s.st_mode) != 0)
@@ -3362,6 +3365,18 @@ strendzap (char *str, const char *pat)
   return str;
 }
 
+void
+lt_debugprintf (const char *fmt, ...)
+{
+  va_list args;
+  if (lt_debug)
+    {
+      va_start (args, fmt);
+      (void) vfprintf (stderr, fmt, args);
+      va_end (args);
+    }
+}
+
 static void
 lt_error_core (int exit_status, const char *mode,
               const char *message, va_list ap)
@@ -3386,9 +3401,9 @@ lt_fatal (const char *message, ...)
 void
 lt_setenv (const char *name, const char *value)
 {
-  LTWRAPPER_DEBUGPRINTF (("(lt_setenv) setting '%s' to '%s'\n",
-                          (name ? name : "<NULL>"),
-                          (value ? value : "<NULL>")));
+  lt_debugprintf ("(lt_setenv) setting '%s' to '%s'\n",
+                  (name ? name : "<NULL>"),
+                  (value ? value : "<NULL>"));
   {
 #ifdef HAVE_SETENV
     /* always make a copy, for consistency with !HAVE_SETENV */
@@ -3436,9 +3451,9 @@ lt_extend_str (const char *orig_value, const char *add, 
int to_end)
 void
 lt_update_exe_path (const char *name, const char *value)
 {
-  LTWRAPPER_DEBUGPRINTF (("(lt_update_exe_path) modifying '%s' by prepending 
'%s'\n",
-                          (name ? name : "<NULL>"),
-                          (value ? value : "<NULL>")));
+  lt_debugprintf ("(lt_update_exe_path) modifying '%s' by prepending '%s'\n",
+                  (name ? name : "<NULL>"),
+                  (value ? value : "<NULL>"));
 
   if (name && *name && value && *value)
     {
@@ -3457,9 +3472,9 @@ lt_update_exe_path (const char *name, const char *value)
 void
 lt_update_lib_path (const char *name, const char *value)
 {
-  LTWRAPPER_DEBUGPRINTF (("(lt_update_lib_path) modifying '%s' by prepending 
'%s'\n",
-                          (name ? name : "<NULL>"),
-                          (value ? value : "<NULL>")));
+  lt_debugprintf ("(lt_update_lib_path) modifying '%s' by prepending '%s'\n",
+                  (name ? name : "<NULL>"),
+                  (value ? value : "<NULL>"));
 
   if (name && *name && value && *value)
     {
diff --git a/tests/cwrapper.at b/tests/cwrapper.at
index 42f8d0f..30a583c 100644
--- a/tests/cwrapper.at
+++ b/tests/cwrapper.at
@@ -79,5 +79,57 @@ for restrictive_flags in '-Wall -Werror' '-std=c89 -Wall 
-Werror' '-std=c99 -Wal
   LT_AT_EXEC_CHECK([./usea], [0], [ignore], [ignore], [])
 done
 
+
+# Make sure wrapper debugging works, when activated at runtime
+# This is not part of the loop above, because we
+# need to check, not ignore, the output.
+CFLAGS="$orig_CFLAGS"
+cat "$orig_LIBTOOL" > ./libtool
+LIBTOOL=./libtool
+
+AT_CHECK([$LIBTOOL --mode=compile $CC $CPPFLAGS $CFLAGS -c liba.c],
+         [], [ignore], [ignore])
+AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -version-info=0.0.0 
-no-undefined -o liba.la -rpath /foo liba.lo],
+         [], [ignore], [ignore])
+AT_CHECK([test -f liba.la])
+
+AT_CHECK([$CC $CPPFLAGS $CFLAGS -c usea.c],
+         [], [ignore], [ignore])
+AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o usea$EXEEXT 
usea.$OBJEXT liba.la],
+         [], [ignore], [ignore])
+LT_AT_EXEC_CHECK([./usea], [0], [ignore], [stderr], [--lt-debug])
+LT_AT_UNIFY_NL([stderr])
+AT_CHECK([grep '^(main) argv\[[0\]][[ \t]]*: \./usea' stderr], [0], [ignore], 
[ignore])
+
+
+# Make sure wrapper debugging works, when activated at compile time.
+# We structure this test as a loop, so that we can 'break' out of it
+# if necessary -- even though the loop by design executes only once.
+for debugwrapper_flags in '-DLT_DEBUGWRAPPER'; do
+  CFLAGS="$orig_CFLAGS $debugwrapper_flags"
+  sed "s/LTCFLAGS=.*/&' $debugwrapper_flags'/" < "$orig_LIBTOOL" > ./libtool
+  LIBTOOL=./libtool
+
+  # make sure $debugwrapper_flags do not cause a failure
+  # themselves (e.g. because a non-gcc compiler doesn't
+  # understand them)
+  $LIBTOOL --mode=compile $CC $CPPFLAGS $CFLAGS -c trivial.c || continue
+
+  AT_CHECK([$LIBTOOL --mode=compile $CC $CPPFLAGS $CFLAGS -c liba.c],
+           [], [ignore], [ignore])
+  AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -version-info=0.0.0 
-no-undefined -o liba.la -rpath /foo liba.lo],
+           [], [ignore], [ignore])
+  AT_CHECK([test -f liba.la])
+
+  AT_CHECK([$CC $CPPFLAGS $CFLAGS -c usea.c],
+           [], [ignore], [ignore])
+  AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o usea$EXEEXT 
usea.$OBJEXT liba.la],
+           [], [ignore], [ignore])
+  LT_AT_EXEC_CHECK([./usea], [0], [ignore], [stderr], [])
+  LT_AT_UNIFY_NL([stderr])
+  AT_CHECK([grep '^(main) argv\[[0\]][[ \t]]*: \./usea' stderr], [0], 
[ignore], [ignore])
+done
+
+
 AT_CLEANUP
 
-- 
1.6.3.2





reply via email to

[Prev in Thread] Current Thread [Next in Thread]