473,385 Members | 1,359 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

how to debug when "Segmentation fault"


Hello,

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

--
Best regards,
Maksim Kasimov
mailto: ma************@gmail.com
Oct 4 '05 #1
9 31888
On Tuesday 04 October 2005 11:13, 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.


What extension modules are you using?

I've never seen "stock" Python (stable release w/ only included modules)
segfault, but did see a segfault with an extension module I was using
the other week (lxml IIRC, but I'm not sure).

- Michael
Oct 4 '05 #2

there are a lot of packeges under suspicion:

cPickle, select, threading, logging, socket, struct
Michael Ekstrand wrote:
On Tuesday 04 October 2005 11:13, 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.

What extension modules are you using?

I've never seen "stock" Python (stable release w/ only included modules)
segfault, but did see a segfault with an extension module I was using
the other week (lxml IIRC, but I'm not sure).

- Michael

--
Best regards,
Maksim Kasimov
mailto: ma************@gmail.com
Oct 4 '05 #3
Maksim Kasimov a écrit :

Hello,

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


Well, your best bet is to generate a core file !
To do so, in the shell launching the program, you need to accept core
files. The command is :

$ ulimit -c <max size of core file accepted>

For example:
$ ulimit -c 500000

For a 500MB max file.

Then, if your program crash, you should see a file named "core.XXXX"
where XXXX is the PID of the process. You can know exactly where the
program crashed using gbd :

$ gdb --core=core.XXXX

Then, depending on the debug information you have in your executables
you may (or may not) be able to know what happened :)

Pierre
Oct 4 '05 #4
On Tue, Oct 04, 2005 at 11:22:24AM -0500, Michael Ekstrand wrote:
[...]
I've never seen "stock" Python (stable release w/ only included modules)
segfault, but did see a segfault with an extension module I was using
the other week (lxml IIRC, but I'm not sure).

- Michael


So far, this is the simplest way to crash stock python, at least in
Unix/Linux;

$ python < /bin

If you redirect directory instead of file, python crashes. I think this bug was
introduced around 2.1 or 2.2, and not yet fixed as of 2.4.1.

- Inyeol
Oct 4 '05 #5

yes, to generete core dump is the best way,

but the command "$ ulimit -c 500000" don't make python to generete core dump in the time of crush.

I would like to know how to run python script so if it crushes than core dump will be genereted.

Thanks
Pierre Barbier de Reuille wrote:
Maksim Kasimov a écrit :
Hello,

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

Well, your best bet is to generate a core file !
To do so, in the shell launching the program, you need to accept core
files. The command is :

$ ulimit -c <max size of core file accepted>

For example:
$ ulimit -c 500000

For a 500MB max file.

Then, if your program crash, you should see a file named "core.XXXX"
where XXXX is the PID of the process. You can know exactly where the
program crashed using gbd :

$ gdb --core=core.XXXX

Then, depending on the debug information you have in your executables
you may (or may not) be able to know what happened :)

Pierre

--
Best regards,
Maksim Kasimov
mailto: ma************@gmail.com
Oct 5 '05 #6
Maksim Kasimov a écrit :

yes, to generete core dump is the best way,

but the command "$ ulimit -c 500000" don't make python to generete core
dump in the time of crush.

I would like to know how to run python script so if it crushes than core
dump will be genereted.

Thanks


If it does not, that probably means the core file is larger ... try a
larger value or even "unlimited" :

$ ulimit -c unlimited

Pierre
Oct 5 '05 #7
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.

--
hardware, n: The parts of a computer system that can be kicked.
Oct 5 '05 #8
On Wed, 05 Oct 2005 14:53:45 +0200, Tamer Fahmy
<ta***@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
Oct 5 '05 #9

looks sad :(

ok, until the decision not found, i've run my script (if someone have the same problem) using sh-script like this:

#!/bin/sh
while true
do
myscript.py
echo "scrip was fault" | mail -s "run.sh" ma************@gmail.com
done

.... still works ;)
Franz Steinhaeusler wrote:
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?

--
Best regards,
Maksim Kasimov
mailto: ma************@gmail.com
Oct 5 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: hvaisane | last post by:
Valgrind says ==11604== Invalid read of size 4 ==11604== at 0x8048ABB: main (foo.cc:36) ==11604== Address 0x1B92415C is 4 bytes inside a block of size 8 free'd ==11604== at 0x1B90514F:...
9
by: mahurshi | last post by:
i have a quick question i am putting a debug flag in my program (i really dont need this feature, but i figured it might be useful when i get into trouble) so i want to check if argv is the...
3
by: eiselekd | last post by:
Does anyone know about a code snippet that can be used to output a backtrace just like gdb's "backtrace" command does. One that can be called on a segmentation fault. (without resolving symbol...
10
by: eyh5 | last post by:
Hi, My C code (running on Soalris Unix) has some "segmentation fault" that I wish to use purify to do it. I poked around the web, and found some information about adding some lines in a Makefile...
9
by: Gary | last post by:
Hi all! I've taken some time on learning the difference between "pointers to const variables" and "const pointer variables". The question is: in the following code, can we change the contents of...
3
by: fantasticamir | last post by:
Guys, DO you know why I got segmentation fault on this piece of code? char p={68,69,98,112,105}; char *p1; for (int i=0; i<5; i++) p1=p; p1='\0'; cout << p1<<endl;
2
by: jimhakans | last post by:
#include<stdio.h> main() { int mark,j,i; for(j=0;j<25;j++) { for(i=0;i<4;i++) { printf("\nEnter you marks\n"); scanf("%d",marks);
1
by: Dameon99 | last post by:
Hi, I have just spent many hours debugging my code and now when I run it I get the following error: "An access violation (Segmentation fault) raised in your program" I have researched on this...
0
by: vendejp | last post by:
I intermittently get the following error when calling a soap method: "HTTP" - Error Fetching http headers. Its really hit or miss... sometimes it works sometimes not. The exception doesn't...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.