Page 1 of 1

How to locate the line that causes the segmentation fault (core dumped)

Posted: Thu Jan 09, 2020 9:19 am
by Ryan
Hey,
I really don't know how to locate the line that causes the the segmentation fault (core dumped). I have tried to used valgrind to find it. And I get the results as follows:

Code: Select all

chris@chris-virtual-machine:~/argos_ws/swarm_physarum$ valgrind --tool=memcheck --leak-check=yes --show-reachable=yes ./libfootbot_physarum_2.so ==7418== Memcheck, a memory error detector ==7418== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. ==7418== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info ==7418== Command: ./libfootbot_physarum_2.so ==7418== ==7418== ==7418== Process terminating with default action of signal 11 (SIGSEGV) ==7418== Access not within mapped region at address 0x0 ==7418== at 0x1: ??? ==7418== by 0x1FFF000006: ??? ==7418== If you believe this happened as a result of a stack ==7418== overflow in your program's main thread (unlikely but ==7418== possible), you can try to increase the size of the ==7418== main thread stack using the --main-stacksize= flag. ==7418== The main thread stack size used in this run was 8388608. ==7418== ==7418== HEAP SUMMARY: ==7418== in use at exit: 0 bytes in 0 blocks ==7418== total heap usage: 0 allocs, 0 frees, 0 bytes allocated ==7418== ==7418== All heap blocks were freed -- no leaks are possible ==7418== ==7418== For counts of detected and suppressed errors, rerun with: -v ==7418== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) Segmentation fault (core dumped)
But I can not understand what is it. Can you give me some advice?

Re: How to locate the line that causes the segmentation fault (core dumped)

Posted: Thu Jan 09, 2020 9:22 am
by pincy
Without the code it's impossible to guess. If you send me your code in a way that is easy to compile and test, I can see what I can find.

Re: How to locate the line that causes the segmentation fault (core dumped)

Posted: Thu Jan 09, 2020 9:49 am
by Ryan
Is it the compiled file in the build folder?
If so, I added the file to the attachment.

Re: How to locate the line that causes the segmentation fault (core dumped)

Posted: Thu Jan 09, 2020 9:57 am
by pincy
I need the source files, not the binaries. Please give them to me in a way that is easy to compile - e.g., just run cmake and make.

Re: How to locate the line that causes the segmentation fault (core dumped)

Posted: Thu Jan 09, 2020 10:12 am
by Ryan
All the files are added in the attachments.
And what I run the file is /controller/footbot_physarum_2
the .xml file is physarum_maze_10*10.argos

Re: How to locate the line that causes the segmentation fault (core dumped)

Posted: Thu Jan 09, 2020 10:19 am
by Ryan
Actually what I more hope is that you can tell me how to debug it.

Re: How to locate the line that causes the segmentation fault (core dumped)

Posted: Fri Jan 10, 2020 3:37 am
by pincy
The original command you shared (valgrind --tool=memcheck --leak-check=yes --show-reachable=yes ./libfootbot_physarum_2.so) is incorrect because valgrind needs an executable to run. The correct command would be

Code: Select all

valgrind --tool=memcheck --leak-check=yes --show-reachable=yes argos3 -c myexperimentfile.argos
where myexperimentfile.argos is the configuration file you want to run.

Regarding how to troubleshoot these problems, the approach I usually employ is to start with printf() statements to narrow down where the error happens, move on to gdb to check the values of variables and pointers, and then use tools such as Asan and Valgrind to understand the cause of the issues.

I compiled and ran your code (physarum_maze_20_20.argos) for about 11000 steps. I had to make a couple of minor changes to your code, but on my machine the experiment never crashed (I don't know what it's supposed to do, so I can't say if it worked correctly).

Specifically, in footbot_physarum.cpp and footbot_physarum_2.cpp I replaced (the line numbers refer to the first file):

Code: Select all

532: Real fitness_prox[tProxReads.size()] = {0};
with:

Code: Select all

532: Real* fitness_prox = new Real[tProxReads.size()]; 533: for(size_t i = 0; i < tProxReads.size(); ++i) fitness_prox[i] = 0.0; ... 578: delete[] fitness_prox;
and in footbot_physarum_2.cpp I added

Code: Select all

947: return false;

Re: How to locate the line that causes the segmentation fault (core dumped)

Posted: Fri Jan 10, 2020 5:22 am
by Ryan
Thank you very much for your detailed answer.I solved it.