Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Compiling with debugger flag -g fixes SEGfault (fortran90) Post 302481526 by Corona688 on Friday 17th of December 2010 07:57:01 PM
Old 12-17-2010
Quote:
Originally Posted by drbones
So the title kinda says it all. I was getting a SEGfault, so I decided to compile with the -g option to find where, and low and behold the SEGfault doesn't occur.

I suppose the answer is "Problem solved! You fixed yet another SEGfault." But I am very curious how this could have happened.
Enabling debugging likely disabled some optimizations, altering the way the code was generated and perhaps the pattern of memory use.

Imagine you're using an uninitialized variable. It may just happen to always be zero when the code isn't optimized since it wasn't used before. But optimize it and it decides it doesn't need a variable at all and puts it in a register! Suddenly you're using an uninitialized register, which could be anything, and it crashes...

Or you're overflowing the end of an array, and the arrangement of memory is different when the executable's optimized. When it's not optimized, you might be corrupting empty space and not care. When it's optimized, you could be munging something important, like pointers to somewhere else, or even your stack frame...

Can you debug it when it's not compiled for debugging? The information you get might be limited, but limited's better than nothing.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

[Linux] How Do I Run Until Segfault

Hello, sorry if this has been posted before but i was wondering if there is a way to run a program until a segmentation fault is found. Currently i'm using a simple shell script which runs my program 100 times, sleeps 1 second because srand(time(0)) is dependent on seconds. Is there a possible... (1 Reply)
Discussion started by: aslambilal
1 Replies

2. Programming

how to avoid the segfault from Address 0x1cd00000103 out of bounds

After allocating memory for some variables, segfault is often to happen, due to the same reason: Address 0x1cd00000103 out of bounds It is welcome to recommend some treatments. Thanks e.g. is_done = 0x1cd00000103 <Address 0x1cd00000103 out of bounds>, hood = 0x23c00000247, c =... (11 Replies)
Discussion started by: cdbug
11 Replies

3. Solaris

Working around netscape 4.9 segfault on Solaris 8

We have a Solaris 8 server which users login to via VNC to get a desktop. On that desktop these users use Netscape Communicator 4.9 to access a very important mail account. Unfortunately Netscape has started segfaulting regularly. Does anyone have any ideas how I can try to find out what point... (1 Reply)
Discussion started by: aussieos
1 Replies

4. Programming

2 Problems: Segfault on ctrl+c and syslog() prob

1. Even if i have the handles for ctrl+c it gives off a segfault 2. syslog doesn't log LOG_ERR event with log masked specified or non specified, it logs LOG_WARNING however... #include <sys/types.h> /* include this before any other sys headers */ #include <sys/stat.h> #include <fcntl.h>... (2 Replies)
Discussion started by: james2432
2 Replies

5. Programming

id3lib SEGFAULT

Hello everyone, I'm writing a program using the id3lib unfortunately I've encountered with memory issue that cause segmentation fault. I tried to rerun and analyze the program with valgrind but it doesn't point me anywhere. I really stuck on this one. Valgrind output: ==14716== Invalid read of... (2 Replies)
Discussion started by: errb
2 Replies

6. Programming

Is Drive Valid Segfault

I have a program that allows users to specify the debug log file location and name. I have tried using the access() and stat() but they both segfault if the drive say (d:\) is invalid. Both seem to be fine if the drive exists. Could someone please point me in the direction to a function that... (1 Reply)
Discussion started by: robfwauk
1 Replies

7. Programming

Alternative debugger to GNU insight debugger

GNU insight debugger is not available now a days and it is required to debug/inspect assembly code as written in the book Assembly Language Programming step by step in Linux so my question is; is there any alternative to insight that I can use instead of insight in which I can get the same... (5 Replies)
Discussion started by: vectrum
5 Replies

8. Programming

segfault in pointer to string program

hello all, my question is not about How code can be rewritten, i just wanna know even though i am not using read only memory of C (i have declared str) why this function gives me segfault :wall:and the other code executes comfortably though both code uses same pointer arithmetic. ... (4 Replies)
Discussion started by: zius_oram
4 Replies

9. Programming

String array iteration causing segfault

I am populating an array of string and print it. But it going in infinite loop and causing segfault. char Name = { "yahoo", "rediff", "facebook", NULL }; main(int argc, char* argv) { int j = 0; ... (7 Replies)
Discussion started by: rupeshkp728
7 Replies

10. Programming

Segfault When Parsing Delimiters In C

Another project, another bump in the road and another chance to learn. I've been trying to open gzipped files and parse data from them and hit a snag. I have data in gzips with a place followed by an ip or ip range sort of like this: Some place:x.x.x.x-x.x.x.x I was able to modify some code... (6 Replies)
Discussion started by: Azrael
6 Replies
BZERO(3)						     Linux Programmer's Manual							  BZERO(3)

NAME
bzero, explicit_bzero - zero a byte string SYNOPSIS
#include <strings.h> void bzero(void *s, size_t n); #include <string.h> void explicit_bzero(void *s, size_t n); DESCRIPTION
The bzero() function erases the data in the n bytes of the memory starting at the location pointed to by s, by writing zeroes (bytes con- taining '') to that area. The explicit_bzero() function performs the same task as bzero(). It differs from bzero() in that it guarantees that compiler optimizations will not remove the erase operation if the compiler deduces that the operation is "unnecessary". RETURN VALUE
None. VERSIONS
explicit_bzero() first appeared in glibc 2.25. ATTRIBUTES
For an explanation of the terms used in this section, see attributes(7). +-----------------+---------------+---------+ |Interface | Attribute | Value | +-----------------+---------------+---------+ |bzero(), | Thread safety | MT-Safe | |explicit_bzero() | | | +-----------------+---------------+---------+ CONFORMING TO
The bzero() function is deprecated (marked as LEGACY in POSIX.1-2001); use memset(3) in new programs. POSIX.1-2008 removes the specifica- tion of bzero(). The bzero() function first appeared in 4.3BSD. The explicit_bzero() function is a nonstandard extension that is also present on some of the BSDs. Some other implementations have a simi- lar function, such as memset_explicit() or memset_s(). NOTES
The explicit_bzero() function addresses a problem that security-conscious applications may run into when using bzero(): if the compiler can deduce that the location to zeroed will never again be touched by a correct program, then it may remove the bzero() call altogether. This is a problem if the intent of the bzero() call was to erase sensitive data (e.g., passwords) to prevent the possibility that the data was leaked by an incorrect or compromised program. Calls to explicit_bzero() are never optimized away by the compiler. The explicit_bzero() function does not solve all problems associated with erasing sensitive data: 1. The explicit_bzero() function does not guarantee that sensitive data is completely erased from memory. (The same is true of bzero().) For example, there may be copies of the sensitive data in a register and in "scratch" stack areas. The explicit_bzero() function is not aware of these copies, and can't erase them. 2. In some circumstances, explicit_bzero() can decrease security. If the compiler determined that the variable containing the sensitive data could be optimized to be stored in a register (because it is small enough to fit in a register, and no operation other than the explicit_bzero() call would need to take the address of the variable), then the explicit_bzero() call will force the data to be copied from the register to a location in RAM that is then immediately erased (while the copy in the register remains unaffected). The problem here is that data in RAM is more likely to be exposed by a bug than data in a register, and thus the explicit_bzero() call creates a brief time window where the sensitive data is more vulnerable than it would otherwise have been if no attempt had been made to erase the data. Note that declaring the sensitive variable with the volatile qualifier does not eliminate the above problems. Indeed, it will make them worse, since, for example, it may force a variable that would otherwise have been optimized into a register to instead be maintained in (more vulnerable) RAM for its entire lifetime. Notwithstanding the above details, for security-conscious applications, using explicit_bzero() is generally preferable to not using it. The developers of explicit_bzero() anticipate that future compilers will recognize calls to explicit_bzero() and take steps to ensure that all copies of the sensitive data are erased, including copies in registers or in "scratch" stack areas. SEE ALSO
bstring(3), memset(3), swab(3) COLOPHON
This page is part of release 4.15 of the Linux man-pages project. A description of the project, information about reporting bugs, and the latest version of this page, can be found at https://www.kernel.org/doc/man-pages/. Linux 2017-09-15 BZERO(3)
All times are GMT -4. The time now is 12:11 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy