1

I am compiling some numerical code with gfortran using Code::Blocks. I have two versions of the executable: Debug and Release.

  • Debug compilation flags: -Jobj\Debug\ -Wall -g -c
  • Release compilation flags: -Jobj\Release\ -Wall -O2 -c
  • gdb invokation flags: -nx -fullname -quiet -args

When I run the code normally, both the Release and Debug executables produce the same output. However, when I run the code in gdb, the output is different. This appears to be due to numerical calculations producing different results during execution.

For example, the result of one calculation when run in gdb is 7.93941842553643E-06 and when run normally is 1.71006041855278E-03. More oddly, some of the non-zero results are identical within double precision accuracy.

How can I ensure that the output is the same when I run using gdb? Is a different type of numerical calculation or evaluation used by default when using gdb?

7
  • You must remove your bugs and undefined behaviours. Which ones? Who knows without seeing your code... Commented Feb 23, 2017 at 12:39
  • I have edited the original question to reflect the fact that I believe the behaviour I am seeing is due to a difference in the way that numerical values are calculated when the code is run using gdb. Commented Feb 23, 2017 at 15:45
  • So how does the computation look like? Commented Feb 23, 2017 at 17:10
  • Do you mean what is the code to produce different answers? It's too complex to post, but I'm trying to narrow it down to a smaller piece of code. Commented Feb 23, 2017 at 17:12
  • 1
    Yes, found it manually: an uninitialised array element. Switching to Linux and valgrind found it very quickly. Commented Feb 27, 2017 at 15:16

1 Answer 1

1

This appears to be due to numerical calculations producing different results during execution.

That is exceedingly unlikely: GDB doesn't participate in any numerical calculations your program executes.

Significantly more likely is that your program uses uninitialized memory, and that memory just happens to have different values when the program runs under GDB.

If you are on a platform that is supported by valgrind, your very first step should be to run your program under it, and fix all bugs it finds.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.