LinuxQuestions.org
Help answer threads with 0 replies.
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 03-10-2009, 02:56 PM   #1
golden_boy615
Member
 
Registered: Dec 2008
Distribution: Ubuntu Fedora
Posts: 445

Rep: Reputation: 17
segmentation fault on arm linux


hello every body.
I have a very serious problem with this simple code.
first of all I have to say that I am using an arm embedded computer with linux.
my code is :

[I]
#include <stdarg.h>
#include "mbserial.h"

#define MAX_BUFFER_SIZE 256


int MBSerialReadHoldingRegisters(int port, u8 address, u16 startreg, u16 no, u16 *value)
{
u8 adu[ MB_ASCII_ADU_MAX_LENGTH], pdu[ MAX_BUFFER_SIZE];
int pdu_len= 0, adu_len= 0, ret= 0;
u8 ret_no;
printf("21\n");
/// make PDU
pdu_len= MBReadHoldingRegisters( pdu, startreg, no);
printf("22\n");
adu_len= MBSerialSendAndWaitResponse( port, adu, pdu, pdu_len, address);
printf("23\n");
if( adu_len < 0)
return adu_len;

pdu_len= MBGetPDU( pdu, adu, adu_len);
ret= MBGetResponseReadHoldingRegisters( pdu, &ret_no, value);
if( ret < 0)
return ret;
return ret_no;
}



int main()
{
int startreg,
reg_no,
port,j=0,i;
unsigned int port_speed;
u16 ret_value[MAX_BUFFER_SIZE];
u8 ret_reg_no;
u8 address = 1;

printf("enter the port number 1 or 2:\n");
scanf("%i",&port);
port = port--;
printf("enter the port speed :\n");
scanf("%i",&port_speed);
printf("enter first register number that you want:\n");
scanf("%i",&startreg);
printf("how many registers you want to see:\n");
scanf("%i",&reg_no);
printf("1\n");

printf("try to open serial port %i ...\n",port+1);
MBSerialInit();
if( MBSerialOpen( port, MB_RTU_PROTOCOL) < 0)
{
perror("serial");
exit( -1);
}
printf("opened..\n");
SerialSetSpeed( port, port_speed);
printf("2\n");
ret_reg_no = MBSerialReadHoldingRegisters(port, address,startreg, reg_no, ret_value);
printf("3\n");
printf("%i registers have these values:\n",ret_reg_no/2);
for ( i=0;i<ret_reg_no/2;i++)
printf("%i\n",ret_value);

master_exit:
return 0;

}




it compiled with no errore and very well but during executing I get:
enter the port number 1 or 2:
1
enter the port speed :
9600
enter first register number that you want:
50000
how many registers you want to see:
1
1
try to open serial port 1 ...
opened..
2
Segmentation fault (core dumped)



I used printf to find out where does it stop as you can see it stops exacly on calling MBSerialReadHoldingRegisters function and did not goes inside(I say it from printf output that I used to debug).
I know that some thing in my call going wrong but I don't know what is it.
I have not gdb on embeded computer but it has gdbserver that I used but it does not help me any more because I rum it ang got this:
-----------------------------------------------------------------
gdbserver /dev/ttyS0 MBSERIALSLAVE core (on embeded)
-----------------------------------------------------------------
arm-linux-gdb (on fedora 8)
GNU gdb 5.3
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 "--host=i686-linux --target=arm-linux".
(gdb) r
Starting program:
Don't know how to run. Try "help target".
(gdb) target remote /dev/ttyS0
Remote debugging using /dev/ttyS0
Couldn't establish connection to remote target
Reply contains invalid hex digit 43
(gdb) target remote /dev/ttyS0
Remote debugging using /dev/ttyS0
Cannot access memory at address 0x0
0x40001b80 in ?? ()
(gdb) next
next nexti
(gdb) next
Cannot find bounds of current function
(gdb) nexti
Cannot access memory at address 0x0
0x40001b84 in ?? ()
(gdb) nexti
Cannot access memory at address 0x0
0x40001b84 in ?? ()
(gdb) nexti
Reply contains invalid hex digit 72
(gdb) nexti
Reply contains invalid hex digit 43
(gdb) nexti
Cannot access memory at address 0x0
Cannot access memory at address 0x0
0x00000000 in ?? ()
(gdb) nexti
Cannot access memory at address 0x0
0x00000000 in ?? ()
(gdb) nexti
Cannot access memory at address 0x0
0x00000000 in ?? ()
(gdb) nexti
Cannot access memory at address 0x0
0x00000000 in ?? ()
(gdb) nexti
Cannot access memory at address 0x0
0x00000000 in ?? ()
(gdb) nexti
Cannot access memory at address 0x0
0x00000000 in ?? ()
------------------------------------------------------------------
but with continue command it work very well but do not give me good information.
(gdb) c
Continuing.

Program received signal SIGSEGV, Segmentation fault.
Ignoring packet error, continuing...
Ignoring packet error, continuing...
---------------------------------------------------------
another big problem that I have is I dont know how to use core file remotely from different machine and different architecture like this situation.
when I copy core file to fedora computer for using with arm-linux-gdb(gdb for my embedded) and using core-file core i get this error:

(gdb) core-file core
GDB can't read core files on this machine.
--------------------------------------------------------------

thank you for any help every body.
 
  


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
Cross-compiled wireless_tools_v29 caused segmentation fault on arm-platform mailerlee Linux - Wireless Networking 0 02-26-2008 05:01 AM
Problem with Segmentation Fault in Linux akzare Programming 2 08-17-2006 12:42 AM
yast segmentation fault, system freezing - nvidia driver at fault? BaltikaTroika SUSE / openSUSE 2 12-02-2005 10:34 AM
Segmentation fault on RedHat Linux 8.0 hemanth_13 Linux - General 2 07-28-2003 06:52 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:30 PM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration