CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Segmentation fault - PCML

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ghamblin



Joined: 02 Aug 2015
Posts: 38
Location: Tucson

View user's profile Send private message

Segmentation fault - PCML
PostPosted: Sun Aug 02, 2015 9:39 am     Reply with quote

I have a problem that I know I've had before, but I can't remember what it was or how I fixed it (Sux to get old).

Anyway, I use MPLAB X in Linux with the PCML compiler. I have taken a project from a customer that was originally built under PCW, and created an MPLAB X project for it. After fixing the normal case issues, and a few other warnings, I attempted to compile it, and the compiler throws this error:

Code:

Runtime error 231 at 08058941
Segmentation fault (core dumped)
mv: cannot stat `build/default/production/c2price.cof': No such file or directory
make[2]: *** [build/default/production/c2price.o] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2


I know I've had this issue in the past, and I know I did something to fix it, I just can't figure it out. I'm hoping someone out there knows.

Have a great day,
_________________
-Glenn
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Aug 02, 2015 1:13 pm     Reply with quote

Based on this old post, it could be code-related:
http://www.ccsinfo.com/forum/viewtopic.php?t=34024&highlight=segmentation+fault

Comment out sections of your program in a binary fashion, do a test
compile, and continue until you find the line of code that is the offender.
ghamblin



Joined: 02 Aug 2015
Posts: 38
Location: Tucson

View user's profile Send private message

PostPosted: Sun Aug 02, 2015 1:31 pm     Reply with quote

Thanks PCM programmer,

I've been doing exactly that. Perhaps I haven't found the culprit yet.

Thanks again,
Glenn
_________________
-Glenn
Ttelmah



Joined: 11 Mar 2010
Posts: 19545

View user's profile Send private message

PostPosted: Sun Aug 02, 2015 1:38 pm     Reply with quote

I'd double check the file permissions on the stuff you have imported.
ghamblin



Joined: 02 Aug 2015
Posts: 38
Location: Tucson

View user's profile Send private message

PostPosted: Sun Aug 02, 2015 4:24 pm     Reply with quote

So I feel like I must have gone down the rabbit hole. I'm commenting stuff out and if I comment the right? lines the compile will not throw a segmentation fault, and of course I get all the errors that you'd expect when you remove variables, but if I uncomment even one of these lines, it will throw the fault. I'm going bananas. Here's what's commented out when the compiler doesn't throw a fault:
Code:

struct SYS_STRUCT
    {
//    int OPMSKA;
//    int PORTDATA;
//    int ACTDEV;   // ACTIVE DEVICE
//    int MODE;  // MAIN SYSTEM MODE
    signed int16 SIWORD;
//    int BTNDOWN;
//    int1  BTNDB;  // DEBOUNCE
//    int1  BTNPROC;   // PROCESSED
//    int1  FAULTVALID;
//      union {
//        int16 IWORD;
//        int8  IBYTE[2];
        } ITEMP;
    } SYS;

struct {
//    int1    PUFLG;       // POWER UP OCCURRED
//    int1    ACTIVE;      // SYSTEM IS ACTIVE
    int1    LCDACT;      // LCD IS ACTIVE
    int1    LCUFLG;     // UPDATE LCD
//    int1    SHOWCTY;
    int1    MS100;
} SYSFLAGS;

Compiling: 
     Keeping c2price.$$$
102 Errors,  0 Warnings, Build Failed.,  Time: 1 Seconds
/home/glenn/MPLABXProjects/C2PRICE.X/c2price.h,  Line 100
Expecting a declaration
make[2]: Leaving directory `/home/glenn/MPLABXProjects/C2PRICE.X'
make[1]: Leaving directory `/home/glenn/MPLABXProjects/C2PRICE.X'

BUILD FAILED (exit value 2, total time: 263ms)


Any thoughts? Should I call the funny farm? :-)
_________________
-Glenn
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Aug 02, 2015 5:13 pm     Reply with quote

The first thing I would suspect is that it doesn't like the int1's, and the
next thing would be that it doesn't like the union.

Try changing all the int1's to int8.

Another possibilty is to do the int1's as bits in a bitfield.
ghamblin



Joined: 02 Aug 2015
Posts: 38
Location: Tucson

View user's profile Send private message

PostPosted: Sun Aug 02, 2015 6:34 pm     Reply with quote

Ttelmah wrote:
I'd double check the file permissions on the stuff you have imported.


That sounds like a real possibility.

PCM programmer wrote:
The first thing I would suspect is that it doesn't like the int1's, and the
next thing would be that it doesn't like the union.

Try changing all the int1's to int8.

Another possibilty is to do the int1's as bits in a bitfield.


I had thought about that, it's not my code and that isn't my style of coding. But that said it compiled just fine at my customers location, and I only needed to make a small change. Unless the V5.028 compiler is that much different than what they're running, I'd expect it to maybe have errors, but just blowing up isn't cool.


I'm going to spend a little more time on this, and then go make the change at my customers location.

Thank you both, I appreciate the help.
_________________
-Glenn
Ttelmah



Joined: 11 Mar 2010
Posts: 19545

View user's profile Send private message

PostPosted: Mon Aug 03, 2015 1:03 am     Reply with quote

As a comment about the int1's, use a bitfield.

In a structure declaration, the 'traditional' way of declaring a variable smaller than an int8, was as bitfields in an int. So:

Code:

struct {
   int8    PUFLG:1;       // POWER UP OCCURRED
   int8    ACTIVE:1;      // SYSTEM IS ACTIVE
   int8    LCDACT:1;      // LCD IS ACTIVE
   int8    LCUFLG:1;     // UPDATE LCD
   int8    SHOWCTY:1;
   int8    MS100:1;
} SYSFLAGS;

This declares an int8, containing 6 one bit fields (and two unused bits).

This is the standard C way of doing this. I'd 'reserve' int1's for standalone variable declarations.
ghamblin



Joined: 02 Aug 2015
Posts: 38
Location: Tucson

View user's profile Send private message

PostPosted: Mon Aug 03, 2015 9:37 am     Reply with quote

Ttelmah wrote:
As a comment about the int1's, use a bitfield.

In a structure declaration, the 'traditional' way of declaring a variable smaller than an int8, was as bitfields in an int. So:

Code:

struct {
   int8    PUFLG:1;       // POWER UP OCCURRED
   int8    ACTIVE:1;      // SYSTEM IS ACTIVE
   int8    LCDACT:1;      // LCD IS ACTIVE
   int8    LCUFLG:1;     // UPDATE LCD
   int8    SHOWCTY:1;
   int8    MS100:1;
} SYSFLAGS;


This declares an int8, containing 6 one bit fields (and two unused bits).

This is the standard C way of doing this. I'd 'reserve' int1's for standalone variable declarations.


I agree completely. This is not my code, and certainly not my coding style. I was hoping to make only a small change to an already working product they have. Actually I just need to do a test and set a flag. So I was hoping not to get that deep into changing stuff. However, I might just get in there and do it, because I've already spent hours trying to get it to compile without blowing up, and I was expecting a 10 minute edit. :-(

Thanks again,
Glenn
_________________
-Glenn
ghamblin



Joined: 02 Aug 2015
Posts: 38
Location: Tucson

View user's profile Send private message

PostPosted: Sat Aug 08, 2015 4:25 pm     Reply with quote

I got desperate and converted all the int1's to bitfields. Sadly no love. Same issue. :-(

Code:



// ************************ registers ************************
struct {
    int OPMSKA;
    int PORTDATA;
    int ACTDEV;   // ACTIVE DEVICE
    //; MAIN SYSTEM MODE
    int MODE;
    union{
        long IWORD;
        int  IBYTE[2];
    } ITEMP;
    signed long SIWORD;
    int BTNDOWN;
    //
    int8  BTNDB:1;  // DEBOUNCE
    int8  BTNPROC:1;   // PROCESSED
    int8  FAULTVALID:1;
} SYS;

struct {
    int8    PUFLG:1;       // POWER UP OCCURRED
    int8    ACTIVE:1;      // SYSTEM IS ACTIVE
    int8    LCDACT:1;      // LCD IS ACTIVE
    int8    LCUFLG:1;     // UPDATE LCD
    int8    SHOWCTY:1;
    int8    MS100:1;
} SYSFLAGS;

struct {
    signed long ESCROW;       //; ESCROW COUNT
    long PRICE;        // price in nickels or 50 centavo
    long CTRYCODE;   //  ISO CURRENCY CODE OR TELEPHONE CODE
    int PRICESW[2];
    int BTNCODE;         // VEND BUTTON CODE
    int COUNTRY;   // COUNTRY NUMBER
    int GPCNT;       // GALLON PULSES TO ISSUE
    long CCPCNT;        // COIN TOTALIZER COUNT
    signed long TKNSUM;      // TOKEN SUM
    // FLAGS
    int8  BTNPREQ:1;  // BUTTON PROCESS REQ
    int8  VPREQ:1;    // VEND PULSE REQ
    int8  ESCZER:1;   // ESCROW IS ZERO
    int8  VSWACT:1;   // VEND SWITCH IS ACTIVE
    int8  CHKRET:1;   // CHECK FOR COIN RETURN
    int8  CBVIP:1;      // COIN/BILL VEND IN PROGRESS
    int8  FREEALL:1;     // free vend
    int8  RETACTIVE:1;
    int8  RETREQ:1;
    int8  CMDAFLG:1;
    int8  CCPCRY:1;
    // TOKENS
    int8  TKCREQ:1;   // count request
    int8  TOKEN:1;
} VEND;

// vend buttons
enum vbcodes{VBX,VB1,VB5 = 5};


//;***
struct {
    int RTMODE;       // SEND/RECEIVE MODE
    int XBCNT;      //  TRANSMIT/RECEIVE BYTE COUNT
    int ICTMR;      // INTER-CHARACTER TIMER
    int CRTMR;      // COMMMAND RESPONSE TIMER
    int CHKSUM;
    int CHKSUMRX;
    int CMDSENT;
    // BYTE LEVEL SEND STATES
    int TXREQ;      // REQUEST MESSAGE SEND
    int TXMODE;     // TRANSMIT MODE
    int *XBPTR;       // SEND/RCV BUFFER POINTER
    //; SERIAL  DATA BYTE
    int XDATABY;
    long XDATAL;
    // FLAGS
    int8 TXDONE :1;
    int8 RXDONE :1;
    int8 RCVFLG :1;
    int8 MSGSENT :1;

} COMMS;
//
struct {
    // TIMER REGISTERS
    int T10MS;
    int T50MS;
    int T1SEC;         // 1 SECOND TIMER
    int T5SEC;         // 5 SECONDS
    int T1MIN;
    int DEAD;        // DEADMAN MIN COUNTER
    int FAULT;
    long TMRX;         // GENERAL TIMER
    int RIDTMR;
    int LCDTMR;
} STIMERS;


struct {
    int XDATA;
    long CTRYCODE;   //  ISO CURRENCY CODE OR TELEPHONE CODE
    int TYPCODE;     // COIN TYPE
    int CREDIT;    // COIN CREDIT
    int SCALE;    // SCALE FACTOR
    int TUBENB;  // TYPES THAT ARE ENABLED FOR TUBES
    int POLLCTR;  // COIN POLL COUNTER
    int NRTMR;    // NO RESPONSE
    int TCVALS[8];  // TUBE COIN COUNTS
    int FEAT;
    // FLAGS
    int8 SETUP:1;     // CHANGER WAS SET UP
    int8 DROP:1;     // COIN DEPOSITED
    int8 CASHBOX:1;    // COIN WENT TO CASH BOX
    int8 RESET:1;      // CHANGER WAS RESET
    int8 POBUSY:1;     // PAYOUT BUSY FLAG
    int8 DISABLED:1;     // CHANGER WAS DISABLED
    // requests
    int8 RESETREQ:1;
    int8 SETUPREQ:1;
    int8 TSTATREQ:1;     // TUBE STATUS REQUESTED
    int8 DISABREQ:1;     // DISABLE REQUEST
    int8 ENABREQ:1;
    int8 DISPREQ:1;    // DISPENSE A COIN
} COIN;

struct {
    int XDATA;
    long CTRYCODE;   //  ISO CURRENCY CODE OR TELEPHONE CODE
    int CREDIT;
    long SCALE;    // SCALE
    int POLLCTR;     // BILL POLL COUNTER
    int NRTMR;    // NO RESPONSE COUNTER
    // FLAGS
    int8    RESET:1;      // BILL VALIDATOR RESET FLAG
    int8    SETUP:1;         // VALIDATOR WAS SETUP
    int8    DISABLEDE:1;      // VALIDATOR WAS DISABLED FOR ESCROW
    int8    DISABLED:1;
    int8    UDISAB:1;    // VALIDATOR REPORTS DISABLED
    int8    VESCROW:1;     // bill in escrow in the validator
    // requests
    int8    RESETREQ:1;
    int8    DISABREQE:1;     // request for disable
    int8    DISABREQ:1;
    int8    ENABREQ:1;
    int8    SETUPREQ:1;
    int8    RETREQ:1;     // request bill return
    int8    STKREQ:1;     // request bill stack
    // actions
    int8    RETGO:1;
    int8    STKGO:1;
    int8    WAITSTK:1;    // wait for stack response
} BILL;

struct {
    int XDATA;
    int RTMODE;    // TRANSMIT MODE
    int SUBCODE;   // MEDIA SUB-CODE
    int SUSTATE;    // setup state
    signed long ESCROW;      // MEDIA ESCROW
    int FEAT;    // FEATURES
    int SCALE;     // SCALE FACTOR
    int DECI;    // DECIMAL POINT
    int APPRSP;     // RESPONSE TIMEOUT SECONDS
    int NRTMR;   // NO RESPONSE COUNTER
    int POLLCTR;
        #define MRPCNT  40
    int ERRCODE;       // error code
    int CMDREQ;      // COMMAND REQUEST CODE
    // MEDIA READER FLAGS
    // FLAGS
    int8    SETUP:1;      // MEDIA WAS SET UP
    int8    SESACT:1;      // MEDIA SESSION ACTIVE
    int8    RESET:1;      // JUST RESET FLAG FROM THE READER
    int8    RESETTX:1;      // Media reset was transmitted
    int8    VIPAG:1;       // Media vend in progress after grant
    int8    WAITVGR:1;      // WAITING FOR GRANT
    int8    VGRANTED:1;      // MEDIA VEND GRANT FROM READER
    int8    DISABTX:1;     // media disable was transmitted
    int8    RDISABACK:1;    // Reader acked the disable message
    int     DISABLED:1;
    // REQ FLAGS
    int8   VSREQ:1;      // REQUEST VEND SUCCESS
    int8    DISABREQ:1;     // request reader disable
    int8    ENABREQ:1;
    int8    IDREQ:1;     // media ID request
    int8    RESETREQ:1;     // reset request
} MEDIA;


_________________
-Glenn
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Aug 08, 2015 5:50 pm     Reply with quote

What's your compiler version ? I don't know if linux versions track the
Windows versions, but we can at least see what it is. The version is given
at the top of the .LST file, i.e., 4.141 or 5.047 etc.

And what is your PIC ?

Also, post the lines from the top of your .LST file, that show the amount
of ROM, RAM, and stack levels that are used.
ghamblin



Joined: 02 Aug 2015
Posts: 38
Location: Tucson

View user's profile Send private message

PostPosted: Sat Aug 08, 2015 6:18 pm     Reply with quote

Compiler PCM 5.028

Chip is 16F76

There is no list file, the compiler just exits with the following:

Code:

Runtime error 231 at 08058941
Segmentation fault (core dumped)
mv: cannot stat `build/default/production/c2price.cof': No such file or directory
make[2]: *** [build/default/production/c2price.o] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2


_________________
-Glenn
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Aug 08, 2015 6:28 pm     Reply with quote

But what if you comment out the minimum number of lines to get it to
compile ? Then there will be a .LST file and you can post the ROM, RAM
and stack usage.
ghamblin



Joined: 02 Aug 2015
Posts: 38
Location: Tucson

View user's profile Send private message

PostPosted: Sat Aug 08, 2015 10:41 pm     Reply with quote

I'll give that a shot and let you know. Thanks.
_________________
-Glenn
ghamblin



Joined: 02 Aug 2015
Posts: 38
Location: Tucson

View user's profile Send private message

PostPosted: Sat Aug 08, 2015 11:02 pm     Reply with quote

Well, by the time I get enough commented out that the compiler doesn't fail, there's too many errors to compile. Mostly undefined identifiers because I've commented out almost all the defined variables. So there's a a ".err file" but nothing else. :-(

Code:

Compiling: 
     Keeping c2price.$$$
104 Errors,  1 Warnings, Build Failed.,  Time: 1 Seconds
c2price.c,  Line 283
Undefined identifier
make[2]: Leaving directory `/home/glenn/MPLABXProjects/c2price.X'
make[1]: Leaving directory `/home/glenn/MPLABXProjects/c2price.X'
mv: cannot stat `build/default/production/c2price.cof': No such file or directory
make[2]: *** [build/default/production/c2price.o] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2

BUILD FAILED (exit value 2, total time: 616ms)

_________________
-Glenn
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group