Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stack Overflow causes valgrind to exit with error #13

Closed
jfrimmel opened this issue Aug 7, 2019 · 1 comment · Fixed by #93
Closed

Stack Overflow causes valgrind to exit with error #13

jfrimmel opened this issue Aug 7, 2019 · 1 comment · Fixed by #93

Comments

@jfrimmel
Copy link
Owner

jfrimmel commented Aug 7, 2019

If the program under test produces a stack overflow, the following output is printed:

    Finished dev [unoptimized + debuginfo] target(s) in 0.24s
   Analyzing `target/debug/huge_box`
==5113==  If you believe this happened as a result of a stack
==5113==  overflow in your program's main thread (unlikely but
==5113==  possible), you can try to increase the size of the
==5113==  main thread stack using the --main-stacksize= flag.
==5113==  The main thread stack size used in this run was 8388608.
==5113==  If you believe this happened as a result of a stack
==5113==  overflow in your program's main thread (unlikely but
==5113==  possible), you can try to increase the size of the
==5113==  main thread stack using the --main-stacksize= flag.
==5113==  The main thread stack size used in this run was 8388608.
error: valgrind command failed

Note, that the normal valgrind output is interleaved with the cargo-valgrind output. This should not happen. Even if valgrind fails, its error messages should be parsed and dispalyed in the custom style.

Investigating of how to suppress the valgrind stack overflow error is required.

@jfrimmel
Copy link
Owner Author

The current output looks like this:

error: invalid valgrind usage: ==1921283== Stack overflow in thread #1: can't grow stack to 0x1ffe801000
==1921283== Stack overflow in thread #1: can't grow stack to 0x1ffe801000
==1921283== Stack overflow in thread #1: can't grow stack to 0x1ffe801000
==1921283==  If you believe this happened as a result of a stack
==1921283==  overflow in your program's main thread (unlikely but
==1921283==  possible), you can try to increase the size of the
==1921283==  main thread stack using the --main-stacksize= flag.
==1921283==  The main thread stack size used in this run was 8388608.

jfrimmel added a commit that referenced this issue Sep 17, 2024
This commit checks for a specific valgrind output string occurring when
a potential stack overflow is detected. The output is "parsed" a bit, in
order to produces a nicer user experience. The output looks like this:

    $ cargo valgrind run --manifest-path tests/corpus/Cargo.toml --bin issue-13
       Error: looks like the program overflowed its stack
        Info: valgrind says:
              ==1937526== Stack overflow in thread #1: can't grow stack to 0x1ffe801000
              ==1937526== Stack overflow in thread #1: can't grow stack to 0x1ffe801000
              ==1937526== Stack overflow in thread #1: can't grow stack to 0x1ffe801000
              ==1937526==  If you believe this happened as a result of a stack
              ==1937526==  overflow in your program's main thread (unlikely but
              ==1937526==  possible), you can try to increase the size of the
              ==1937526==  main thread stack using the --main-stacksize= flag.
              ==1937526==  The main thread stack size used in this run was 8388608.

This clearly states the most likely cause of the error and thus helps a
user to search the error. The actual valgrind output is written there as
well, since it contains the help how to diagnose this more/mitigate a
potential false positive by creating a bigger stack.

Fixes #13.
jfrimmel added a commit that referenced this issue Sep 17, 2024
This commit checks for a specific valgrind output string occurring when
a potential stack overflow is detected. The output is "parsed" a bit, in
order to produces a nicer user experience. The output looks like this:

    $ cargo valgrind run --manifest-path tests/corpus/Cargo.toml --bin issue-13
       Error: looks like the program overflowed its stack
        Info: valgrind says:
              ==1937526== Stack overflow in thread #1: can't grow stack to 0x1ffe801000
              ==1937526== Stack overflow in thread #1: can't grow stack to 0x1ffe801000
              ==1937526== Stack overflow in thread #1: can't grow stack to 0x1ffe801000
              ==1937526==  If you believe this happened as a result of a stack
              ==1937526==  overflow in your program's main thread (unlikely but
              ==1937526==  possible), you can try to increase the size of the
              ==1937526==  main thread stack using the --main-stacksize= flag.
              ==1937526==  The main thread stack size used in this run was 8388608.

This clearly states the most likely cause of the error and thus helps a
user to search the error. The actual valgrind output is written there as
well, since it contains the help how to diagnose this more/mitigate a
potential false positive by creating a bigger stack.

Fixes #13.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant