LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 02-10-2007, 11:57 PM   #1
cybil001
Member
 
Registered: Jan 2007
Posts: 32

Rep: Reputation: 15
Exclamation Segmentation fault


hey!
i m trying to run a bluetooth acces point prog ...but it gives a Segmentation fault n then stops

wats the prob???

tnx

 
Old 02-11-2007, 12:18 AM   #2
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
From what you have said it is impossible for anyone to tell you what the problem is.

A segmentation fault occurs when a program is trying to access memory it is not permitted to access. There are many ways in which this can happen.

Did you write the program yourself?
Did you compile it from provided source code?
Did you install it from a package manager?

To get a meaningful answer from this forum we would need to know about the lines in error. If you don't have the source then I suspect that a more productive approach would be to contact the developers.
 
Old 02-11-2007, 12:32 AM   #3
cybil001
Member
 
Registered: Jan 2007
Posts: 32

Original Poster
Rep: Reputation: 15
Exclamation

well i got the source code from a friend of mine whos not available right now n i hav the source code with me! wat else??
 
Old 02-11-2007, 01:46 AM   #4
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
You will need to compile it with debugging information, which language is used? C, C++, another? How did you compile the code with gcc, make?

For a C compiler you will want to use the -g flag in gcc
For make maybe the following will help: make debug=yes

Once it is compiled with debugging information then you need to use a debugger to tell you where the problem occurs. Maybe your friend can help you with all of this.
 
Old 02-11-2007, 09:37 AM   #5
cybil001
Member
 
Registered: Jan 2007
Posts: 32

Original Poster
Rep: Reputation: 15
Exclamation

well i ran make debug=yes n got no info.

[root@miru zoneIT]# make debug=yes
gcc -ggdb rsa.o communication.o scanner.o zoneIT.o directory.o linkedlist.o -o z oneIT -lbluetooth -lm -lpthread
just this was displayed

i told in my last post that i got this from a friend of mine who is no longer available n i want this to function properly. its kind of urgent.

Last edited by cybil001; 02-11-2007 at 09:54 AM.
 
Old 02-11-2007, 09:55 AM   #6
cybil001
Member
 
Registered: Jan 2007
Posts: 32

Original Poster
Rep: Reputation: 15
Exclamation

n this is how i m receiving the error:
 
Old 02-11-2007, 09:56 AM   #7
cybil001
Member
 
Registered: Jan 2007
Posts: 32

Original Poster
Rep: Reputation: 15
Exclamation

[root@miru zoneIT]# ./zoneIT
zoneIT Access Point application Usage: zoneIT -d 500 -p 1 (default use) -d directory_size500Scanning all BT devices ...
found 00:0A:D9:60:E3:6C
no of threads running is 0
The bluetooth address 00:0A:D9:60:E3:6C is not found, trying to access...
no of threads running is 1
Completed screening all scanned devices

The address connect from : 00:00:00:00:00:00
The address to connect is: 6C:E3:60:D9:0A:00
Can't connect to 00:0A:D9:60:E3:6C, Operation already in progress(114)
Waiting for threads to finish, 1 threads are runnning.Waiting for threads to finish, 0 threads are runnning.Completed access control procedures 0 times.
*****************************************************************************************

Segmentation fault


should i give the source code??

Last edited by cybil001; 02-11-2007 at 10:05 AM.
 
Old 02-11-2007, 10:09 AM   #8
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
Are you prepared to post the source code? Please do not just paste pages and pages of code into the forums - I'm asking the question if you are prepared to. Before answering you should probably review license terms for the software - is it legal to post the code in public?

If it's open source and that you can post the code, and you do post the code, you may find someone who will help you debug it. If not, I would recommend hiring a programmer with relevant experience to do it.
 
Old 02-12-2007, 02:04 AM   #9
cybil001
Member
 
Registered: Jan 2007
Posts: 32

Original Poster
Rep: Reputation: 15
Exclamation

well i have said earlier that it is my friends project n now i need it to work! so i m pasting the link here of the whole prog. it is in ".rar" format n u hav to extract the files first:

http://rapidshare.com/files/16122474/zoneIT.rar.html

tnx!



 
Old 02-12-2007, 03:25 PM   #10
slzckboy
Member
 
Registered: May 2005
Location: uk - Reading
Distribution: slack 10.2 kde 3.4.2 kernel 2.6.15
Posts: 452

Rep: Reputation: 30
sucker for punishment..

I thought I would have a go at this but I think I'm out of my depth.

valgrind output
Code:
Invalid read of size 4
==27848==    at 0x1B969947: pthread_setschedparam (in /lib/tls/libpthread-2.3.5.so)
==27848==    by 0x804A8C0: scanAllDevices (zoneIT.c:240)
==27848==    by 0x804A6C1: main (zoneIT.c:139)
==27848==  Address 0x48 is not stack'd, malloc'd or (recently) free'd
==27848==
==27848== Process terminating with default action of signal 11 (SIGSEGV)
==27848==  Access not within mapped region at address 0x48
==27848==    at 0x1B969947: pthread_setschedparam (in /lib/tls/libpthread-2.3.5.so)
==27848==    by 0x804A8C0: scanAllDevices (zoneIT.c:240)
==27848==    by 0x804A6C1: main (zoneIT.c:139)
offending function...

Code:
int scanAllDevices(){
        //priority doesn't matter much when using SCHED_OTHER policy
        extern struct sched_param param1;
        extern struct sched_param param2;
        memset(&param1,0,sizeof(param1));
        memset(&param2,0,sizeof(param2));
        int priority1=4;
        int priority2=4;
        int count ;
        int policy1,policy2,policy3;
        int ret =0;
        // thread schedule
        param1.sched_priority = priority1;
        param2.sched_priority = priority2;

        // set detatchable attribute to scanner
        pthread_attr_t attr1;
        pthread_attr_init(&attr1);
        pthread_attr_setdetachstate(&attr1, PTHREAD_CREATE_JOINABLE);
        pthread_t scanner;
        memset(&scanner,0,sizeof(scanner));
        policy1 = SCHED_FIFO;   
        policy2 = SCHED_OTHER;  
        policy3 = SCHED_RR;   

/******** (zoneIT.c:139) below as per ***************/

    ret += pthread_setschedparam(scanner, policy2, &param1);
        ret += pthread_create(&scanner, &attr1, scan_all_dev, arg);
        ret += pthread_join(scanner, NULL);

        return ret;
}
re

Quote:
Address 0x48 is not stack'd, malloc'd or recently free'd
How can i trace this meory address back to the offending variable in the source code???

yours stupidly

slzkboy.
 
Old 02-12-2007, 10:19 PM   #11
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
Okay it looks af if the offending line is 240 in the file zoneIT.c
Code:
==27848==    by 0x804A8C0: scanAllDevices (zoneIT.c:240)
==27848==    by 0x804A6C1: main (zoneIT.c:139)
==27848==  Address 0x48 is not stack'd, malloc'd or (recently) free'd
zoneIT.c:240 This means file zoneIT.c line number 240
from zoneIT.c:139 you can tell where the function scanAllDevices() was called from, which is sometimes useful. (line 139)
 
Old 02-12-2007, 11:07 PM   #12
cybil001
Member
 
Registered: Jan 2007
Posts: 32

Original Poster
Rep: Reputation: 15
Exclamation

so..? wat do i do now?

 
Old 02-13-2007, 01:19 AM   #13
slzckboy
Member
 
Registered: May 2005
Location: uk - Reading
Distribution: slack 10.2 kde 3.4.2 kernel 2.6.15
Posts: 452

Rep: Reputation: 30
sorry graemef I was getting tired yesterday

the line that i said was /****zoneIT.c:139*****/

is infact zoneIT.c:240.
Its the call to pthread_setschedparam()

Code:
ret += pthread_setschedparam(scanner, policy2, &param1);
I have looked at the parameters with gdb and they seem to be initialised ok?!

Cybil001

You just need to be patient to see if someone can debug this code.
Even if I/we find the problem to what is causing this initial crash there may be other bugs else where!??

So fingers crossed thats not the case.
 
Old 02-13-2007, 01:40 AM   #14
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
Can anyone replicate the crash?

I have to say I didn't try yet because I'm not familiar with the bluetooth API, and I don't actually have a fully working bluetooth device.
 
Old 02-13-2007, 01:59 AM   #15
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
I'm no expert on threads, but my guess is that the thread (scanner) hasn't been set up properly. What might be required is:
Code:
        ret += pthread_create(&scanner, &attr1, scan_all_dev, arg);
        ret += pthread_setschedparam(scanner, policy2, &param1);
As I understand it pthread_setschedparam() is expecting a valid thread ID, which pthread_create() establishes. So a blind stab in the dark would be to switch those two lines around. Sorry not very convincing but might be worth a shot.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
yast segmentation fault, system freezing - nvidia driver at fault? BaltikaTroika Suse/Novell 2 12-02-2005 09:34 AM
Segmentation fault ( C ) wenta0 Programming 4 12-22-2004 05:10 AM
Segmentation fault marios_auth Programming 1 06-16-2004 08:16 AM
segmentation fault Linh Programming 6 11-03-2003 08:25 AM
segmentation fault? sgm Programming 1 01-25-2003 08:41 PM


All times are GMT -5. The time now is 07:30 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration