Re: [Valgrind-users] How can valgrind prevent Segmentation fault?

2019-01-26 Thread John Perry
I had a problem like last May, though it may not have been the same problem. In 
my case it was the optimization settings. I typically used -O0 for valgrind, 
and at -O0 the program didn’t crash. At level -O1 or higher it always crashed. 
I can’t recall if I ran it in valgrind at -O1 or higher, but if I did then that 
didn’t help me find the problem, either.

In the end I combed through the code where the problem was occurring, and 
discovered that I had forgotten to return a value from a function that was 
declared to return bool. I hadn’t noticed the compiler warning in the 20 
screens of Makefile messages that scrolled by.

I hope that’s somehow helpful.

john perry

> On Jan 26, 2019, at 5:12 PM, Peng Yu  wrote:
> 
> Hi,
> 
> I have an executable. If I just run on its own, there will be
> segmentation fault. But if I run it using valgrind, it finishes
> successfully. Does anybody how can this happen? How to debug such a
> program? Thanks.
> 
> -- 
> Regards,
> Peng
> 
> 
> ___
> Valgrind-users mailing list
> Valgrind-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/valgrind-users


___
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users


Re: [Valgrind-users] How can valgrind prevent Segmentation fault?

2019-01-26 Thread John Reiser

On 1/26/19, Eliot Moss wrote:

On 1/26/2019, Peng Yu wrote:


I have an executable. If I just run on its own, there will be
segmentation fault. But if I run it using valgrind, it finishes
successfully. Does anybody how can this happen? How to debug such a
program? Thanks.


Maybe not the sort of answer you have in mind, but I might start
with using gdb.  It should still segfault under those conditions.
You can then try recompiling to -g to get debug symbols


As Eliot says, SIGSEGV is easy.  Run under gdb until the SIGSEGV occurs,
then get a backtrace of subroutine calls, and look around.  If necessary,
then re-compile with -g to get more symbols.

On modern Intel x86_64 hardware (or on a "friendly" virtual machine) and with
lots of disk space, then try "Record and Replay":  https://rr-project.org/
(The videos are excellent!)
Re-played execution is *exactly* the same every time, so in the
worst case then binary search on the number of executed instructions
is a valid technique.

'rr' can even run the program "backwards", which is extremely useful.
Stop at the error, put a breakpoint on the entry to the current subroutine,
execute backwards to that breakpoint.  Then step forward by statement
or instruction, watching control flow, values of variables, etc.


___
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users


Re: [Valgrind-users] How can valgrind prevent Segmentation fault?

2019-01-26 Thread Alan Corey
A segfault is usually a bad pointer or something pointing outside
allocated space.  Why it stops segfaulting when you run it through
Valgrind I don't know.  Compile with -g for either Valgrind or gdb,
and if it still runs in Valgrind try gdb.  You can just do gdb
 then you'll probably have to type run in gdb.  At least
if it segfaults in there you can do a backtrace and maybe figure out
why.  Compiling with -g will usually enable gdb to print out bits of
your code when it stops so you may recognize where it is.  Google
something like "gdb segfault tutorial", you usually have to pick a
frame I think.

hmm, umass, I used to work there until 2009.

On 1/26/19, Eliot Moss  wrote:
> On 1/26/2019 6:12 PM, Peng Yu wrote:
>
>> I have an executable. If I just run on its own, there will be
>> segmentation fault. But if I run it using valgrind, it finishes
>> successfully. Does anybody how can this happen? How to debug such a
>> program? Thanks.
>
> Maybe not the sort of answer you have in mind, but I might start
> with using gdb.  It should still segfault under those conditions.
> You can then try recompiling to -g to get debug symbols.  Doing
> that might affect whether the bug exhibits, but it would make
> debugging easier.
>
> Valgrind might be useful if you think the fault has to do with
> improper freeing or lack of initialization of pointers ...
>
> Regards - Eliot Moss
>
>
> ___
> Valgrind-users mailing list
> Valgrind-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/valgrind-users
>


-- 
-
No, I won't  call it "climate change", do you have a "reality problem"? - AB1JX
Cities are cages built to contain excess people and keep them from
cluttering up nature.
Impeach  Impeach  Impeach  Impeach  Impeach  Impeach  Impeach  Impeach


___
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users


Re: [Valgrind-users] How can valgrind prevent Segmentation fault?

2019-01-26 Thread Eliot Moss

On 1/26/2019 6:12 PM, Peng Yu wrote:


I have an executable. If I just run on its own, there will be
segmentation fault. But if I run it using valgrind, it finishes
successfully. Does anybody how can this happen? How to debug such a
program? Thanks.


Maybe not the sort of answer you have in mind, but I might start
with using gdb.  It should still segfault under those conditions.
You can then try recompiling to -g to get debug symbols.  Doing
that might affect whether the bug exhibits, but it would make
debugging easier.

Valgrind might be useful if you think the fault has to do with
improper freeing or lack of initialization of pointers ...

Regards - Eliot Moss


___
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users


Re: [Valgrind-users] How can valgrind prevent Segmentation fault?

2019-01-26 Thread Philippe Waroquiers
On Sat, 2019-01-26 at 17:12 -0600, Peng Yu wrote:
> Hi,
> 
> I have an executable. If I just run on its own, there will be
> segmentation fault. But if I run it using valgrind, it finishes
> successfully. Does anybody how can this happen? How to debug such a
> program? Thanks.
Is valgrind reporting some errors ?
If yes, which kind of errors ?
Philippe



___
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users


[Valgrind-users] How can valgrind prevent Segmentation fault?

2019-01-26 Thread Peng Yu
Hi,

I have an executable. If I just run on its own, there will be
segmentation fault. But if I run it using valgrind, it finishes
successfully. Does anybody how can this happen? How to debug such a
program? Thanks.

-- 
Regards,
Peng


___
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users