]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
When allocating space for the client stack on Linux, take notice of
authorJulian Seward <jseward@acm.org>
Sat, 15 Dec 2007 22:13:05 +0000 (22:13 +0000)
committerJulian Seward <jseward@acm.org>
Sat, 15 Dec 2007 22:13:05 +0000 (22:13 +0000)
the --max-stackframe value.  This makes it possible to run programs
with very large (primary) stack requirements simply by specifying
--max-stackframe.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@7300

coregrind/m_initimg/initimg-linux.c
coregrind/m_main.c
coregrind/m_stacktrace.c

index d6705524f54e83f05fb52a46f1a5a693979f7583..c41f2b756b0e2933ced772d5be39143fe15f83f0 100644 (file)
@@ -859,13 +859,25 @@ IIFinaliseImageInfo VG_(ii_create_image)( IICreateImageInfo iicii )
    //   p: fix_environment() [for 'env']
    //--------------------------------------------------------------
    {
+      /* When allocating space for the client stack on Linux, take
+         notice of the --max-stackframe value.  This makes it possible
+         to run programs with very large (primary) stack requirements
+         simply by specifying --max-stackframe. */
       void* init_sp = iicii.argv - 1;
       SizeT m1  = 1024 * 1024;
       SizeT m16 = 16 * m1;
+      SizeT msf = VG_(clo_max_stackframe) + m1;
       VG_(debugLog)(1, "initimg", "Setup client stack\n");
+      /* For the max stack size, use the client's stack rlimit, but
+         clamp it to between 1M and 16M. */
       iifii.clstack_max_size = (SizeT)VG_(client_rlimit_stack).rlim_cur;
       if (iifii.clstack_max_size < m1)  iifii.clstack_max_size = m1;
       if (iifii.clstack_max_size > m16) iifii.clstack_max_size = m16;
+      /* However, if --max-stackframe= is specified, and the given
+         value (+ 1 M for spare) exceeds the current setting, use the
+         max-stackframe input instead. */
+
+      if (iifii.clstack_max_size < msf) iifii.clstack_max_size = msf;
       iifii.clstack_max_size = VG_PGROUNDUP(iifii.clstack_max_size);
 
       iifii.initial_client_SP
@@ -877,11 +889,15 @@ IIFinaliseImageInfo VG_(ii_create_image)( IICreateImageInfo iicii )
 
       VG_(debugLog)(2, "initimg",
                        "Client info: "
-                       "initial_IP=%p initial_SP=%p initial_TOC=%p brk_base=%p\n",
+                       "initial_IP=%p initial_TOC=%p brk_base=%p\n",
                        (void*)(iifii.initial_client_IP), 
-                       (void*)(iifii.initial_client_SP),
                        (void*)(iifii.initial_client_TOC),
                        (void*)VG_(brk_base) );
+      VG_(debugLog)(2, "initimg",
+                       "Client info: "
+                       "initial_SP=%p max_stack_size=%ld\n",
+                       (void*)(iifii.initial_client_SP),
+                       (SizeT)iifii.clstack_max_size );
    }
 
    //--------------------------------------------------------------
index ee12b8dfaa0cb954fe65d7089356e063c93392f3..64b3a6e763fac5237e57563b0a536c69fd1f80d5 100644 (file)
@@ -244,7 +244,8 @@ static void usage_NORETURN ( Bool debug_help )
 
 
 /* Peer at previously set up VG_(args_for_valgrind) and extract any
-   request for help and also the tool name. */
+   request for help and also the tool name, and also set up
+   VG_(clo_max_stackframe). */
 
 static void get_helprequest_and_toolname ( Int* need_help, HChar** tool )
 {
@@ -276,7 +277,13 @@ static void get_helprequest_and_toolname ( Int* need_help, HChar** tool )
       // here.
       } else if (VG_CLO_STREQN(7, str, "--tool=")) {
          *tool = &str[7];
-      }
+
+      // Set up VG_(clo_max_stackframe).  This is needed by
+      // VG_(ii_create_image), which happens before
+      // process_command_line_options().
+      } else VG_NUM_CLO (str, "--max-stackframe",
+                              VG_(clo_max_stackframe));
+
    }
 }
 
@@ -368,6 +375,9 @@ static Bool process_cmd_line_options( UInt* client_auxv, const char* toolname )
       else VG_BOOL_CLO(arg, "--error-limit",      VG_(clo_error_limit))
       else VG_NUM_CLO (arg, "--error-exitcode",   VG_(clo_error_exitcode))
       else VG_BOOL_CLO(arg, "--show-emwarns",     VG_(clo_show_emwarns))
+      /* Already done in get_helprequest_and_toolname, but we need to
+         redundantly handle it again, so the flag does not get
+         rejected as invalid. */
       else VG_NUM_CLO (arg, "--max-stackframe",   VG_(clo_max_stackframe))
       else VG_BOOL_CLO(arg, "--run-libc-freeres", VG_(clo_run_libc_freeres))
       else VG_BOOL_CLO(arg, "--show-below-main",  VG_(clo_show_below_main))
index 1c474a5d330d3f76781408f9ca803bdb20e2b2fe..3831a700f67f0c738232a38522b5582123142d32 100644 (file)
@@ -97,11 +97,9 @@ UInt VG_(get_StackTrace2) ( ThreadId tid_if_known,
    /* Assertion broken before main() is reached in pthreaded programs;  the
     * offending stack traces only have one item.  --njn, 2002-aug-16 */
    /* vg_assert(fp_min <= fp_max);*/
-
-   if (fp_min + VG_(clo_max_stackframe) <= fp_max) {
-      /* If the stack is ridiculously big, don't poke around ... but
-         don't bomb out either.  Needed to make John Regehr's
-         user-space threads package work. JRS 20021001 */
+   if (fp_min + 512 >= fp_max) {
+      /* If the stack limits look bogus, don't poke around ... but
+         don't bomb out either. */
       ips[0] = ip;
       return 1;
    }