1

My problem is fairly simple: running the 'python' command (not a script) on my raspberry pi model A+ running Raspbian Wheezy gives a segmentation fault:

pi@raspberrypi ~ $ python
Segmentation fault

I found quite a number of threads dealing with 'segmentation fault' in python scripts (often related to external C modules). Some others more specifically on raspberry pi were often speaking of 'segmentation fault' during an apt-get upgrade, involving a python module (here or there).

But those are not answering my problem.

Running it in gdb gave:

pi@raspberrypi ~ $ gdb python
GNU gdb (GDB) 7.4.1-debian
Copyright (C) 2012 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-gnueabihf".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /usr/bin/python...BFD: /usr/bin/python: invalid string offset 4204450 >= 26547 for section `.dynstr'
BFD: /usr/bin/python: invalid string offset 34425 >= 26547 for section `.dynstr'
BFD: /usr/bin/python: invalid string offset 276647 >= 26547 for section `.dynstr'
...
(50 or so such lines later)
...
BFD: /usr/bin/python: invalid string offset 2340624285 >= 26547 for section `.dynstr'
(no debugging symbols found)...done.
(gdb) run
Starting program: /usr/bin/python 

Program received signal SIGSEGV, Segmentation fault.
0xb6ff0124 in ?? () from /lib/ld-linux-armhf.so.3
(gdb) backtrace
#0  0xb6ff0124 in ?? () from /lib/ld-linux-armhf.so.3
#1  0xbefff358 in ?? ()
Cannot access memory at address 0x7a626964

I found this related post, but no clear solution is given.

Last element: python3 works just fine.

Would anyone here have an idea of what is happening?

Thanks for your help ~

Community
  • 1
  • 1
keuj6
  • 103
  • 2
  • 2
  • 8
  • Did you try run in gdb? – CrazyCasta Jul 04 '15 at 17:21
  • Thanks for the answer CrazyCasta. Sorry, what do you mean by 'run in gdb'? Isn't the 'gdb python' I mention in my question enough? If not, could you please be a bit more specific? – keuj6 Jul 04 '15 at 20:43
  • Running `gdb program_name` just starts up the debug environment, it doesn't actually try to run the program. All those messages are basically it saying that it's having trouble reading debug symbols (meaning the debugging out will be harder to read, not that the program itself is having trouble). In order to get any useful information out of gdb about where the segfault is occuring you need to run the program (by typing `run` at the `(gdb)` prompt and hitting enter). – CrazyCasta Jul 04 '15 at 20:45
  • I ran the run and backtrace commands and edited my question. The post I mention suggests to enter 'handle SIGSEGV nostop' (SIGILL actually in there case) to gdb before run. But I have no idea what it would result into. I do not want to completely waste my pi system. – keuj6 Jul 04 '15 at 21:51

3 Answers3

4

The messages you’re getting from GDB when running Python suggest the Python executable you’re trying to use is for some reason corrupted. Try reinstalling all Python-related packages:

$ sudo apt-get install --reinstall `dpkg --get-selections | grep -E '^(lib)?python' | cut -f1 | cut -d: -f1`
icktoofay
  • 126,289
  • 21
  • 250
  • 231
  • 1
    It solved my problem! I tried a `--reinstall python` before but it was of course not enough. Just for the footnotes of history: I got some segfaults in the reinstall process, until I replaced the corrupted package I suppose (either python-serial or python-tk I'd say). I then did an `apt-get update`, where packages that raised segfaults above appeared `in a very bad inconsistent state`. I finally reinstalled them again. My system seems now safe and sound. Many thanks to you @icktoofay and @CrazyCasta – keuj6 Jul 04 '15 at 22:39
1

I had a similar problem where python3 was segfaulting, but apt could not install or remove packages because it invokes /usr/bin/apt-listchanges, a Python 3 script that couldn't execute.

At one point I received the message cannot open /var/lib/dpkg/info/parted.list (Structure needs cleaning) which suggested that there was some filesystem corruption. So if you encounter this issue, see if this is the case.

I created the /forcefsck file to force a filesystem repair on the next boot. The system didn't come back up—better have a serial cable and a spare SD card ready.

If it had come back up, I would have run apt install python3-dbg to download the GDB debugging extensions, even if apt would eventually crash — you could install manually with sudo dpkg -i /var/cache/apt/archives/python3.7-dbg*.deb.

rgov
  • 3,516
  • 1
  • 31
  • 51
0

I had a similar problem on a Raspberry Pi, in my case with Python2. Like @rgov and @icktoofay suggest I had a corrupted binary. gdb wouldn't even load the binary. After a forced fsck, sudo dpkg -i /var/cache/apt/python2.7* fixed this problem, and I was then able to do a sudo apt --fix-broken install. It's possible that my card is failing, or that low power quality is causing write failures.

mangrove
  • 31
  • 2