LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Segfault in Python 3.x test script (http://www.linuxquestions.org/questions/programming-9/segfault-in-python-3-x-test-script-796174/)

grail 03-17-2010 09:42 PM

Segfault in Python 3.x test script
 
So Python noob question, but here goes, I have issued the following
at a command prompt:

>python3 test_AES.py

and receive:

.python[13026]: segfault at ffffffffffffffff ip ffffffffffffffff sp 00007fffa2234778 error 14
Segmentation fault

My question is, can someone suggest how I would go about debugging where my problem is?

I have tried to use pdb but am not real familiar with options.
Please let me know if there is further detail required?

Cheers
Grail

rnesius 03-24-2010 09:29 AM

I'm going to guess the issue isn't your python code, but rather the fact there is a mismatch between shared libraries somewhere. What modules does your script use?

grail 03-24-2010 09:58 AM

hey mesius ... wasn't sure anyone was going to help on this one.

You are 100% correct about the shared libraries. I have converted (or in the process of) the Pycrypto module
to be Python3.X compatible. I am able to run my own small scripts using the likes of AES, Blowfish encryptions,
but i am receiving this segfault when I am trying to run the built in tests that came with it.

To make it simple I am happy to look at just one of the libraries and when pointed in the right direction
will tackle the others myself. To this end I have been trying to find a way to debug AES.so which was created as
part of the install. Are you able to help me understand the best way to debug this shared library?

I have added the -g option to the compilation and if I do a simple - gdb AES.so it tells me that it loads
all necessary symbols, but of course when I then run and backtrace I am not lead to any intelligible errors.

When searching on google it says that the best way to debug a shared library is to compile it into
another program, but the issue I have here is I would not know what sort of program to write to
illicit the correct outcome :(

Please let me know what sort of information I can provide to further this effort?

rnesius 03-25-2010 10:13 AM

It's been awhile since I've debugged shared libraries - it can be tricky. Often times the problem isn't with the main library you are working with, but rather the problem is an compatibility with a library that is being depended on. So to see what libraries AES.so needs, use the 'ldd' command.

* ldd AES.so # should show you the libraries AES.so depends on.
* ldd -r AES.so # forces the loader to resolve all of the symbols - which will sniff out symbols that can't be found in any libraries.

By the way - make sure the libraries being found are the ones it should be finding. A common problem is that the loader grabs a version of a library out of /usr/lib instead of from your test area. You can use the LD_LIBRARY_PATH or SHLIB_PATH environment variables to give a list of paths to prefer over the default system paths, which are defined in /etc/ld.so.conf (usually).

-Rob

grail 03-26-2010 02:34 AM

So ldd - AES.so gives:

Quote:

linux-vdso.so.1 => (0x00007fff04dfe000)
libpython3.1.so.1.0 => /usr/lib/libpython3.1.so.1.0 (0x00007f08fc7ac000)
libpthread.so.0 => /lib/libpthread.so.0 (0x00007f08fc590000)
libc.so.6 => /lib/libc.so.6 (0x00007f08fc235000)
libintl.so.8 => /usr/lib/libintl.so.8 (0x00007f08fc029000)
libdl.so.2 => /lib/libdl.so.2 (0x00007f08fbe25000)
libutil.so.1 => /lib/libutil.so.1 (0x00007f08fbc21000)
libm.so.6 => /lib/libm.so.6 (0x00007f08fb99e000)
/lib64/ld-linux-x86-64.so.2 (0x00007f08fcda0000)
I am assuming from this output that all the symbols have been found?

rnesius 03-26-2010 02:39 PM

Yes - this means the loader was able to resolve all of the symbols.

This means the problem is a bit (actually, a lot) more subtle. Are you able to do very limited tests with the python script to see if it's possible to invoke the script without provoking the segfault? If so, try to map python code to functionality in the library you're porting. That will help get you "in the right neighborhood". Sorry I can't offer better advice than that... without the ability to poke and prod at this myself I can only offer some high-level advice.

-Rob

grail 03-28-2010 01:18 AM

Hi Rob

Thanks for the input. Yes I am able to utilise the python code without invoking the segfault.
i was happily doing so until I tried to run the built in tests, which I am guessing are doing
things I haven't tried as yet :(
I will try as you have suggested and see how I go.

Cheers


All times are GMT -5. The time now is 11:29 AM.