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

Requests regarding how to set up experiments in ARGoS.
Ryan
Posts: 42
Joined: Wed Oct 23, 2019 3:26 am

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

Postby Ryan » Thu Jan 09, 2020 9:19 am

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?

pincy
Site Admin
Posts: 632
Joined: Thu Mar 08, 2012 8:04 pm
Location: Boston, MA
Contact:

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

Postby pincy » Thu Jan 09, 2020 9:22 am

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.
I made ARGoS.

Ryan
Posts: 42
Joined: Wed Oct 23, 2019 3:26 am

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

Postby Ryan » Thu Jan 09, 2020 9:49 am

Is it the compiled file in the build folder?
If so, I added the file to the attachment.
Attachments
footbot_physarum_2.zip
(521.25 KiB) Downloaded 759 times

pincy
Site Admin
Posts: 632
Joined: Thu Mar 08, 2012 8:04 pm
Location: Boston, MA
Contact:

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

Postby pincy » Thu Jan 09, 2020 9:57 am

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.
I made ARGoS.

Ryan
Posts: 42
Joined: Wed Oct 23, 2019 3:26 am

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

Postby Ryan » Thu Jan 09, 2020 10:12 am

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
Attachments
swarm_physarum.zip
(6.67 MiB) Downloaded 757 times

Ryan
Posts: 42
Joined: Wed Oct 23, 2019 3:26 am

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

Postby Ryan » Thu Jan 09, 2020 10:19 am

Actually what I more hope is that you can tell me how to debug it.

pincy
Site Admin
Posts: 632
Joined: Thu Mar 08, 2012 8:04 pm
Location: Boston, MA
Contact:

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

Postby pincy » Fri Jan 10, 2020 3:37 am

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;
I made ARGoS.

Ryan
Posts: 42
Joined: Wed Oct 23, 2019 3:26 am

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

Postby Ryan » Fri Jan 10, 2020 5:22 am

Thank you very much for your detailed answer.I solved it.


Return to “How to... ?”