From: Julian Seward Date: Sat, 15 Dec 2007 22:13:05 +0000 (+0000) Subject: When allocating space for the client stack on Linux, take notice of X-Git-Tag: svn/VALGRIND_3_4_0~1128 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ee4b37fb8e38b4b7b593a4b738ecf30fb9306aab;p=thirdparty%2Fvalgrind.git 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. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@7300 --- diff --git a/coregrind/m_initimg/initimg-linux.c b/coregrind/m_initimg/initimg-linux.c index d6705524f5..c41f2b756b 100644 --- a/coregrind/m_initimg/initimg-linux.c +++ b/coregrind/m_initimg/initimg-linux.c @@ -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 ); } //-------------------------------------------------------------- diff --git a/coregrind/m_main.c b/coregrind/m_main.c index ee12b8dfaa..64b3a6e763 100644 --- a/coregrind/m_main.c +++ b/coregrind/m_main.c @@ -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)) diff --git a/coregrind/m_stacktrace.c b/coregrind/m_stacktrace.c index 1c474a5d33..3831a700f6 100644 --- a/coregrind/m_stacktrace.c +++ b/coregrind/m_stacktrace.c @@ -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; }