Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Segmentation fault when in shared object

Reply
Thread Tools

Segmentation fault when in shared object

 
 
micro.q@gmail.com
Guest
Posts: n/a
 
      09-17-2012
Hello,

I have a piece of code what handles a serial device. I made a test program which get a number of the serial port. When I use these same code in a shared object I get a segmentation fault on the serial functions tcgetattr of tcsetattr. I've verified that with gdb. The shared object is used by net-snmp.

My serial code is almost similar to http://code.google.com/p/as3-arduino...ws-x86/rs232.c
I've only changed to get it working with parity.

Because the code is working as executable I think it has something to do with the rights the application has to write to the settings.

Joram
 
Reply With Quote
 
 
 
 
micro.q@gmail.com
Guest
Posts: n/a
 
      09-18-2012
Op maandag 17 september 2012 16:29:36 UTC+2 schreef (E-Mail Removed) het volgende:
> Hello,
>
>
>
> I have a piece of code what handles a serial device. I made a test program which get a number of the serial port. When I use these same code in a shared object I get a segmentation fault on the serial functions tcgetattr oftcsetattr. I've verified that with gdb. The shared object is used by net-snmp.
>
>
>
> My serial code is almost similar to http://code.google.com/p/as3-arduino...ws-x86/rs232.c
>
> I've only changed to get it working with parity.
>
>
>
> Because the code is working as executable I think it has something to do with the rights the application has to write to the settings.
>
>
>
> Joram


I've made some test code with only the necessary code. Here it is for download:
http://dl.dropbox.com/u/19997801/code.zip

LibTest
"make" to create libTest.so shared object
"make test" to create executable which handles the serial port directly(this one is working)

TestLib
"make" to create executable which loads libTest.so(this gives a segmentation fault)
 
Reply With Quote
 
 
 
 
Johann Klammer
Guest
Posts: n/a
 
      09-18-2012
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> Hello,
>
> I have a piece of code what handles a serial device. I made a test program which get a number of the serial port. When I use these same code in a shared object I get a segmentation fault on the serial functions tcgetattr of tcsetattr. I've verified that with gdb. The shared object is used by net-snmp.
>
> My serial code is almost similar to http://code.google.com/p/as3-arduino...ws-x86/rs232.c
> I've only changed to get it working with parity.
>
> Because the code is working as executable I think it has something to do with the rights the application has to write to the settings.
>
> Joram


Did you try strace and gdb yet? If it is some trivial bug, it will show
up right away. I do not think, anyone here will want to do this for
you... Also, most people seem to filter out news from google groups, sou
you might be more successful posting questions, if you used a different
newsclient.
 
Reply With Quote
 
Ben Bacarisse
Guest
Posts: n/a
 
      09-18-2012
(E-Mail Removed) writes:

> I've made some test code with only the necessary code. Here it is for
> download: http://dl.dropbox.com/u/19997801/code.zip


Full marks for making a small test case. However... it does not compile
for me but the reasons are off-topic here.

> LibTest
> "make" to create libTest.so shared object
> "make test" to create executable which handles the serial port
> directly(this one is working)
>
> TestLib
> "make" to create executable which loads libTest.so(this gives a
> segmentation fault)


There seems to be no C issue on the code (it's short enough to review a
few minutes) so the problem is most likely something very specific to
your system. comp.unix.programming is the place to ask.

--
Ben.
 
Reply With Quote
 
Noob
Guest
Posts: n/a
 
      09-18-2012
micro.q wrote:

> I have a piece of code what handles a serial device. I made a test
> program which get a number of the serial port. When I use these same
> code in a shared object I get a segmentation fault on the serial
> functions tcgetattr of tcsetattr. I've verified that with gdb. The
> shared object is used by net-snmp.


The chaps in comp.arch.embedded might be able to help you.

 
Reply With Quote
 
Kaz Kylheku
Guest
Posts: n/a
 
      09-18-2012
On 2012-09-18, Johann Klammer <(E-Mail Removed)1.net> wrote:
> (E-Mail Removed) wrote:
>> shared object I get a segmentation fault on the serial functions tcgetattr
>> of tcsetattr. I've verified that with gdb. The shared object is used by

^^^^^^^^^^^^^^^^^^^^^^^^^^^^

[...]

> Did you try strace and gdb yet?


!
 
Reply With Quote
 
Johann Klammer
Guest
Posts: n/a
 
      09-18-2012
Kaz Kylheku wrote:
> On 2012-09-18, Johann Klammer<(E-Mail Removed)1.net> wrote:
>> (E-Mail Removed) wrote:
>>> shared object I get a segmentation fault on the serial functions tcgetattr
>>> of tcsetattr. I've verified that with gdb. The shared object is used by

> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>
> [...]
>
>> Did you try strace and gdb yet?

>
> !

oops... getting senile
 
Reply With Quote
 
Kaz Kylheku
Guest
Posts: n/a
 
      09-18-2012
On 2012-09-17, (E-Mail Removed) <(E-Mail Removed)> wrote:
> Hello,
>
> I have a piece of code what handles a serial device. I made a test program
> which get a number of the serial port. When I use these same code in a shared
> object I get a segmentation fault on the serial functions tcgetattr of
> tcsetattr. I've verified that with gdb. The shared object is used by
> net-snmp.
>
> My serial code is almost similar to http://code.google.com/p/as3-arduino...ws-x86/rs232.c
> I've only changed to get it working with parity.
>
> Because the code is working as executable I think it has something to do with
> the rights the application has to write to the settings.


This is incorrect reasoning. Because the code works without dynamic shared
library loading, I would think that it has absolutely nothing to do with
permissions on the tty.

When X works, but X* doesn't, usually the fault is attributable to whatever
has changed between X and X*, not whatever is common.

The difference is either directly responsible for the problem, or
somehow reveals a latent problem. In this case, the difference is in the
dynamic linking. Whether or not you're using dynamic linking isn't going
to have an effect on the tty accessibility.

You also don't understand your gdb. When you get a segfault "on" the
tgetattr function, it's actually a fault in the line of code which calls the
function, not inside the function itself.

What's causing the problem in your code is that you named a global variable
"error". This is the name of a function in the GNU C library. (You might even
have a man page on this: man error).

This is like if you had an "int printf;" or "int fcntl;" variable.

Try putting the statement "error = 0" as the first statement of your
OpenComport and see where the segfault is now.
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      09-18-2012
Ben Bacarisse <(E-Mail Removed)> writes:
[...]
> There seems to be no C issue on the code (it's short enough to review a
> few minutes) so the problem is most likely something very specific to
> your system. comp.unix.programming is the place to ask.


It's comp.unix.programmer.

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
Will write code for food.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
Ben Bacarisse
Guest
Posts: n/a
 
      09-18-2012
Keith Thompson <(E-Mail Removed)> writes:

> Ben Bacarisse <(E-Mail Removed)> writes:
> [...]
>> There seems to be no C issue on the code (it's short enough to review a
>> few minutes) so the problem is most likely something very specific to
>> your system. comp.unix.programming is the place to ask.

>
> It's comp.unix.programmer.


Silly. Thanks. The OP found it none the less and had an answer within
two hours.

--
Ben.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Segmentation fault using Firefox 15.0.2 Keith Lee Firefox 3 04-29-2006 05:45 PM
I'm losing the address of an object... segmentation fault! ChristophK C++ 8 02-24-2006 04:50 PM
segmentation fault on delete object (which belongs to some class under a hierarchy) Joel C++ 4 10-11-2004 05:07 AM
Intel Xeon + Linux + IBM sdk 1.3.1 - getting Segmentation fault Alex Hunsley Java 17 11-06-2003 12:12 AM
built with --enable-shared but get error: libpython2.3.so.1.0: can't open shared object file Douglass Turner Python 2 09-04-2003 01:56 PM



Advertisments