Welcome to the most active Linux Forum on the web.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 03-10-2009, 01:56 PM   #1
Registered: Dec 2008
Distribution: Ubuntu Fedora
Posts: 445

Rep: Reputation: 18
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 :

#include <stdarg.h>
#include "mbserial.h"

#define MAX_BUFFER_SIZE 256

int MBSerialReadHoldingRegisters(int port, u8 address, u16 startreg, u16 no, u16 *value)
int pdu_len= 0, adu_len= 0, ret= 0;
u8 ret_no;
/// make PDU
pdu_len= MBReadHoldingRegisters( pdu, startreg, no);
adu_len= MBSerialSendAndWaitResponse( port, adu, pdu, pdu_len, address);
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,
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");
port = port--;
printf("enter the port speed :\n");
printf("enter first register number that you want:\n");
printf("how many registers you want to see:\n");

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

return 0;


it compiled with no errore and very well but during executing I get:
enter the port number 1 or 2:
enter the port speed :
enter first register number that you want:
how many registers you want to see:
try to open serial port 1 ...
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

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.


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 04:01 AM
Problem with Segmentation Fault in Linux akzare Programming 2 08-16-2006 11:42 PM
yast segmentation fault, system freezing - nvidia driver at fault? BaltikaTroika SUSE / openSUSE 2 12-02-2005 09:34 AM
Segmentation fault on RedHat Linux 8.0 hemanth_13 Linux - General 2 07-28-2003 05:52 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:57 PM.

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