Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segmentation Fault using globale variables #8

Closed
VincentLorenzo opened this issue Jun 24, 2016 · 6 comments
Closed

Segmentation Fault using globale variables #8

VincentLorenzo opened this issue Jun 24, 2016 · 6 comments

Comments

@VincentLorenzo
Copy link

VincentLorenzo commented Jun 24, 2016

I thank you for the last fix about global variable, but it seems is not enough to fix my problems. I continue to get segmentation fault declaring global variable.

To reproduce my problem, you can edit the file ev3dev-lang-demo.cpp, replacing the full main() method by :

large_motor m{OUTPUT_A};
int main()
{
bool connected = m.connected();
if(connected){
printf("connected");
}else{
printf("not connected");
}
m.set_duty_cycle_sp(100);
m.run_forever();
m.set_duty_cycle_sp(0);
  main_menu();
  return 0;
}

The problem can be reproduce with all motors and sensors. It seems be the const like OUTPUT_A which are not yet initialized when we call them, but not sure.

@ddemidov
Copy link
Owner

I could reproduce the problem before 7e84d91, but not after. Can you run the program with gdb, and show the backtrace after the program crashes here?
Something like this:

gdb ./issue-8 
Reading symbols from ./issue-8...done.
(gdb) r
Starting program: /home/demidov/work/ev3/ev3dev-lang-cpp/build/tests/issue-8 

Program received signal SIGSEGV, Segmentation fault.
std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::size (this=0x10)
    at /build/gcc/src/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/basic_string.h:790
790 /build/gcc/src/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/basic_string.h: No such file or directory.
(gdb) bt
#0  std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::size (this=0x10)
    at /build/gcc/src/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/basic_string.h:790
...
#19 0x0000000000426509 in _start ()
(gdb) 

@VincentLorenzo
Copy link
Author

VincentLorenzo commented Jun 28, 2016

I confirm I can reproduce the segfault after 7e84d91. I confirm that replace OUTPUT_A by "outA and large_motor by "lego-ev3-l-motor" in the construtor of the large_motor allow to remove the segfault.

my backtrace:

root@is227212:/tst# qemu-arm-static -g 1234 ev3dev-lang-demo & [1] 12518 root@is227212:/tst# gdb ev3dev-lang-demo GNU gdb (Debian 7.7.1+dfsg-5) 7.7.1 Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "arm-linux-gnueabi".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ev3dev-lang-demo...done.
(gdb) target remote localhost:1234
Remote debugging using localhost:1234
Reading symbols from /lib/ld-linux.so.3...Reading symbols from /usr/lib/debug//lib/arm-linux-gnueabi/ld-2.19.so...done.
done.
Loaded symbols for /lib/ld-linux.so.3
0xf67ced40 in _start () from /lib/ld-linux.so.3
(gdb) c
Continuing.

Program received signal SIGSEGV, Segmentation fault.
0xf676ea50 in std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::string const&) () from
/usr/lib/arm-linux-gnueabi/libstdc++.so.6
(gdb) bt
#0  0xf676ea50 in std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::string const&) () from
/usr/lib/arm-linux-gnueabi/libstdc++.so.6
#1  0x00020eac in ev3dev::motor::motor (this=this@entry=0x325a4 <m>, address=address@entry="4", t=<error reading variable: Cannot access memory at address 0xfffffff4>) at
/export/home/admin-local/git/testSegFaultev3dev/ev3dev-lang-cpp/ev3dev.cpp:771
#2  0x00021134 in ev3dev::large_motor::large_motor (this=0x325a4 <m>,
address=...) at
/export/home/admin-local/git/testSegFaultev3dev/ev3dev-lang-cpp/ev3dev.cpp:800
#3  0x000106f8 in __static_initialization_and_destruction_0
(__initialize_p=<optimized out>, __priority=<optimized out>) at
/export/home/admin-local/git/testSegFaultev3dev/ev3dev-lang-cpp/demos/ev3dev-lang-demo.cpp:822
#4  _GLOBAL__sub_I__ZlsRSoRKSt3setISsSt4lessISsESaISsEE () at
/export/home/admin-local/git/testSegFaultev3dev/ev3dev-lang-cpp/demos/ev3dev-lang-demo.cpp:837
#5  0x00025bf0 in __libc_csu_init ()
#6  0xf64ad25c in __libc_start_main (main=0xf6fffc34, argc=-161636352, argv=0xf64ad25c <__libc_start_main+168>, init=0x25ba0 <__libc_csu_init>,
fini=0x25c04 <__libc_csu_fini>, rtld_fini=0xf67de630 <_dl_fini>,
stack_end=0xf6fffc34) at libc-start.c:246
#7  0x00011598 in _start ()

@ddemidov
Copy link
Owner

Can you please test if 009cdc3 resolves the issue for you?

@VincentLorenzo
Copy link
Author

Yes and not!
Yes it resolves my issues. Thank you very much, but our last commit (or the previous one) seems broken others things.
running ev3dev-lang-demo and trying to play with motor, I get an exception:

*** main menu ***

(s)ensors
(m)otors
(l)eds
(b)uttons
s(o)und
b(a)ttery
l(c)d
(q)uit

Choice: m

*** motor menu ***

(1) lego-ev3-l-motor motor on port outA

(b)ack

Choice: 1

*** lego-ev3-l-motor motor (outA) actions ***

(i)nfo
(c)ommand
terminate called after throwing an instance of 'std::system_error'
what(): /sys/class/tacho-motor/motor0/stop_action: No such dev

@ddemidov
Copy link
Owner

what(): /sys/class/tacho-motor/motor0/stop_action: No such dev

stop_action attribute was added in one of the latest kernels (see announcement here: http://www.ev3dev.org/news/2016/04/11/Kernel-Release-Cycle-10/). What kernel version do you use?

@VincentLorenzo
Copy link
Author

OK, in this case, the problem comes from me! I didn't see this change. I use 3.16.7-ckt21-9-ev3dev-ev3. I don't have the time to update now and check with the new kernel. So It is ok for me. Once gain, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants