1

I get a Segmentation fault (Address not found). The outcome I receive looks something like this:

#3    Object "/some/dir/bin/myProject", at 0x415526, in 
#2    Object "/some/dir/bin/myProject", at 0x40d3f9, in 
#1    Object "/some/dir/bin/myProject", at 0x409b1a, in 
#0    Object "/lib64/libpthread.so.0", at 0x7f9a82a78cd0, in pthread_mutex_lock

I would like to know to which command the positions translate in myProject.cpp. How can I do that?

The reason why I do not examine this with gdb is that this error is caused by the way multiple threads communicate and human intervention introduces so much wait time that this error does not happen. The error is also sporadic...

Additional question:

My understanding of the error Address not found is that this is probably caused by dereferencing a nullprt or when trying to access a container at the wrong place. Would you agree?

EDIT

Thank`s for suggesting to debug the core dump files. The problem with this is: When there is this error, the program does not crash! The error (or a similar one) is printed to console and the program gets stuck (multithreading again...). It does not terminate, so I guess that there are no dump files (correct me if I am wrong!). I could not find any...

User12547645
  • 6,955
  • 3
  • 38
  • 69
  • **You'll need to debug it with gdb**- there's really no other way. For runtime errors like this, OS can only detect that there *is* an error. Your OS is kicking back with the seg fault but it knows nothing about what line of code from `myProject.cpp` is running - all it knows is the compiled assembly code. It can't tell you a line. – alteredinstance Feb 06 '20 at 19:06
  • 2
    seems you need to build with debug symbols on. When the app crashes it will create a core on linux file that will have the info you need. No idea on windows though... – testfile Feb 06 '20 at 19:06
  • @testfile I am on Linux and I am building with debug symbols. Tell me what to do – User12547645 Feb 06 '20 at 19:08
  • [What is a debugger and how can it help me diagnose problems?](https://stackoverflow.com/q/25385173/5910058) – Jesper Juhl Feb 06 '20 at 19:08
  • 1
    @JesperJuhl He stated in the post he knows how to debug - he just won't due to it being some kind of race condition – alteredinstance Feb 06 '20 at 19:09
  • @JesperJuhl I do know how to debug. Multithreading problem. Please read the question – User12547645 Feb 06 '20 at 19:10
  • If your are building with debug symbols, then gdb fails to load them by some reason. – ks1322 Feb 06 '20 at 19:10
  • 2
    "Tell me what to do" - Load the core dump into your debugger, ask for a stack trace, investigate from there *or* run the program in the debugger, inspect the stack trace, variables etc from there when it breaks on your error. In short: debug the problem. – Jesper Juhl Feb 06 '20 at 19:11
  • @ks1322 No. GDB works just fine. I can execute gdb, set breakpoints and be happy about it. The problem is that I do not get the error, when using GDB – User12547645 Feb 06 '20 at 19:11
  • @JesperJuhl Okay. I will try this https://stackoverflow.com/questions/5115613/core-dump-file-analysis – User12547645 Feb 06 '20 at 19:13
  • So you are debugging a core dump? How are you getting the stacktrace above? – ks1322 Feb 06 '20 at 19:14
  • To elaborate on @JesperJuhl this [link](https://www.bogotobogo.com/cplusplus/debugging_core_memory_dump_segmentation_fault_gdb.php) also has a decent explanation of how to get and load a core dump – alteredinstance Feb 06 '20 at 19:14
  • 1
    Threading issues can be a pain to debug since the debugger may change timing between threads. I find [rr](https://rr-project.org/) to be a great help for such problems, as well as [ThreadSanitizer](https://clang.llvm.org/docs/ThreadSanitizer.html). You may want to investigate both. – Jesper Juhl Feb 06 '20 at 19:16
  • Thank you! I will need some time to play with this and (hopefully) find stuff. I will come back to you later tomorrow :) – User12547645 Feb 06 '20 at 19:21
  • 1
    Related: [How to use the addr2line command in Linux](https://stackoverflow.com/questions/7648642/how-to-use-the-addr2line-command-in-linux) – Mark Plotnick Feb 06 '20 at 19:26
  • Thank you for the suggestions with the core dump files. Please see the edit... – User12547645 Feb 06 '20 at 20:02
  • @MarkPlotnick Thank you for the suggestion. Using gdb to make sense of the symbols already helped. I will investigate further... – User12547645 Feb 07 '20 at 09:48
  • @JesperJuhl rr seems to be an amazing tool, but I am on CentOS. Seems like I cannot use it... – User12547645 Feb 07 '20 at 10:50
  • 1
    @User12547645 I'm using it on CentOS 7. Built it from source with devtoolset-8 - works fine. – Jesper Juhl Feb 07 '20 at 15:28

0 Answers0