-2

I have created a c code for a real-time project. I'm using an Ubuntu 15.04 and the code crash with this result(gdb):

     Program received signal SIGSEGV , Segmentation fault.
     [Switching to thread 0x7fffeb7fe700 (LWP 4072)]
     __GI___pthread_mutex_lock (mutex=0xfffffffeb5c6dcb0)
     at ../nptl/pthread_mutex_loxk.c:67
     67       ../nptl/pthread_mutex_lock.c: File o directory non esistente

Tiping : (gdb) x/i $pc the following message appear on the screen:

     => 0x7ffff7bc4c84 <__GI___pthread_mutex_lock+4>:   move  0x10(%rdi),%edx

Can the problem be caused by stackoverflow? How can I solve the problem? Is it possible to know the exact code's row in which the crash appear?

Sourav Ghosh
  • 133,132
  • 16
  • 183
  • 261
  • Possible duplicate of [Line number of segmentation fault](http://stackoverflow.com/questions/505465/line-number-of-segmentation-fault) – Mr. Llama Oct 01 '15 at 17:16
  • 2
    Is that `mutex*` in kernel-memory? Where did you get *that* pointer from? – EOF Oct 01 '15 at 17:18
  • I have defined an array of `mutex*` and its attribute as global variable: `pthread_mutex_t mux[6]; pthread_mutexattr_t matt`. Then I inizialized them into the main `pthread_mutexattr_init(&matt); pthread_mutexattr_setprotocol(&matt,PTHRED_PRIO_INHERIT); for(int i=0;i<6;i++){pthread_mutex_init(&mux[i],&matt)}`. In the thread the code recall the mutex in this way: `pthread_mutex_lock(&mux[index])` where `index` is reported to the right pthread. Thank you @EOF – Gabriele Tovani Oct 02 '15 at 08:51

1 Answers1

1

I'd suggest using Valgrind to help trace these kind of errors. Also, be sure to pass the -g option to gcc so that line numbers and source lines show up when you're debugging.

dbush
  • 205,898
  • 23
  • 218
  • 273
  • I used `valgrind --track-origins=yes ./name`: ==2915== Conditional jump or move depends on uninitialized value(s)` and `Uninitialized value was created by a stack allocation`. Thank you @dbush – Gabriele Tovani Oct 02 '15 at 08:59
  • @GabrieleTovani Glad I could help. Feel free to [accept this answer](http://stackoverflow.com/help/accepted-answer) if you found it useful. – dbush Oct 02 '15 at 10:57