how to debug when "Segmentation fault"

Franz Steinhaeusler franz.steinhaeusler at gmx.at
Wed Oct 5 09:07:49 EDT 2005


On Wed, 05 Oct 2005 14:53:45 +0200, Tamer Fahmy
<tamer at remove-this-tammura.at-and.this> wrote:

>On Tue, 04 Oct 2005 19:13:10 +0300, Maksim Kasimov wrote:
>> my programm sometime gives "Segmentation fault" message (no matter how
>> long the programm had run (1 day or 2 weeks). And there is nothing in
>> log-files that can points the problem. My question is how it possible to
>> find out where is the problem in the code? Thanks for any help.
>> 
>> Python 2.2.3
>> FreeBSD
>
>you could start your program within a gdb session like so:
>
>$ gdb python
>GNU gdb 6.1.1 [FreeBSD]
>Copyright 2004 Free Software Foundation, Inc. GDB is free software,
>covered by the GNU General Public License, and you are welcome to change
>it and/or distribute copies of it under certain conditions. Type "show
>copying" to see the conditions. There is absolutely no warranty for GDB. 
>Type "show warranty" for details. This GDB was configured as
>"i386-marcel-freebsd"...(no debugging symbols found)...
>(gdb) r foo.py
>Starting program: /usr/bin/python foo.py ...
>
>once your progmam segfaults you can then inspect the stack through:
>
>(gdb) bt
>
>cheers,
>  tamer.


Tamer, thanks for your tip.

I tried Jeff's code:

import marshal
f = lambda: None
code =
marshal.loads(marshal.dumps(f.func_code).replace('d\0\0S','d\xff\xffS'))
f.func_code = code
f()

saved it as foo.py, than

C:\Python24\Lib>gdb python
GNU gdb 5.1.1 (mingw experimental)
Copyright 2002 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you
are
welcome to change it and/or distribute copies of it under certain
conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for
details.
This GDB was configured as "mingw32"...(no debugging symbols found)...
(gdb) r foo.py
Starting program: C:\Python24/python.exe foo.py

Program received signal SIGSEGV, Segmentation fault.
0x1e027b23 in ?? ()
(gdb) bt
#0  0x1e027b23 in ?? ()
#1  0x00977240 in ?? ()
#2  0x1e1a82b8 in ?? ()
Cannot access memory at address 0x7
(gdb)

How can I interpret this results? ;)

Am I right, that I need a debug build of python built with mingw or
cygwin in Windows?
-- 
Franz Steinhaeusler



More information about the Python-list mailing list