How to debug this segmentation error?

Moving to a newer version of the CC compiler, a segmentation error occurred in a module that previously worked.

Observations so far:

  • From the main file, I could find out in which segmentation function an error occurred. When I watched this function, I could not find anything suspicious.

  • The first serious problem was that the seg error was reproduced only when compiling to "release" (optimization was turned on) and did not play on "debug". Also, the seg error is not reproducible in g ++.

  • Now I started using print, and there was a big problem - when adding cout / printf (to the binary search for the seg fault line / printing the value of pointers) to certain lines of code, the code seg fault didn Play Moreover, I put cout on a specific line in the code that supported the seg error, which supposedly means that the seg error occurs before this line. Commenting out the lines after , this line made the seg error disappear.

For me, this screams memory corruption (in particular, the stack), but I have no idea how to move on this without looking at the generated assembly.

Any ideas? thanks in advance.

I am working on SunOS_5.10_Studio_12_5.12_64, CC version "Sun C ++ 5.12 SunOS_sparc 2011/11/16"

More information that arose from the questions in the comments:

  • The code is single threaded.
  • valgrind is not available on Solaris, so it is not relevant
+6
source share
1 answer

You should use a debugger / memory profiler like valgrind . He will quickly tell you about the place of corruption. On Solaris, you can try libumem .

+2
source

Source: https://habr.com/ru/post/921322/


All Articles