Hot!PIC24F debugging fun

Page: 123 > Showing page 1 of 3
Author
friesen
Super Member
  • Total Posts : 1724
  • Reward points : 0
  • Joined: 2008/05/08 05:23:35
  • Location: Indiana, USA
  • Status: online
2017/09/11 11:25:43 (permalink)
0

PIC24F debugging fun

I am using xc16 1.32b with an icd3 and pic24fj128ga704.
 
Debug builds are not doing the same thing as production builds, and I really don't know why.  It is semi random stuff that would appear like a stack overflow.  As stated though, debugging works perfect, and the same code on a production build does odd stuff.  Adding code seems to make the problem move to some other random location.
 
Any ideas what I may be overlooking?
 
Is it possible to debug a production build?
 

Erik Friesen
#1

55 Replies Related Threads

    KTrenholm
    Super Member
    • Total Posts : 253
    • Reward points : 0
    • Joined: 2012/08/08 14:04:23
    • Location: Connecticut, USA
    • Status: online
    Re: PIC24F debugging fun 2017/09/11 11:28:00 (permalink)
    3 (1)
    As long as you turn off optimizations for your production build you should be able to debug it just fine.  If the code has been optimized, you'll often see jumping around while stepping with the debugger and you'll also see variables optimized out.
    #2
    friesen
    Super Member
    • Total Posts : 1724
    • Reward points : 0
    • Joined: 2008/05/08 05:23:35
    • Location: Indiana, USA
    • Status: online
    Re: PIC24F debugging fun 2017/09/11 11:35:11 (permalink)
    0
    I am not sure how to do that in mplabX however.

    Erik Friesen
    #3
    friesen
    Super Member
    • Total Posts : 1724
    • Reward points : 0
    • Joined: 2008/05/08 05:23:35
    • Location: Indiana, USA
    • Status: online
    Re: PIC24F debugging fun 2017/09/11 11:54:29 (permalink)
    0
    Or could running a large Code and Data model cause some weird issues?
     

    Erik Friesen
    #4
    KTrenholm
    Super Member
    • Total Posts : 253
    • Reward points : 0
    • Joined: 2012/08/08 14:04:23
    • Location: Connecticut, USA
    • Status: online
    Re: PIC24F debugging fun 2017/09/11 12:01:59 (permalink)
    4.5 (2)
    As far as optimization goes, it's in the project properties.
    Project Properties>XC16 (Global Options)>xc16-gcc>Optimizations
    From there you can modify your optimization level.  0 is no optimization, and if you haven't touched the settings, I believe it's the default.
     
    Unfortunately I'm not familiar enough with the different code/data models to say if that could be your issue.  Someone else would have to chime in.
    #5
    friesen
    Super Member
    • Total Posts : 1724
    • Reward points : 0
    • Joined: 2008/05/08 05:23:35
    • Location: Indiana, USA
    • Status: online
    Re: PIC24F debugging fun 2017/09/11 12:04:28 (permalink)
    0
    I know about optimization, but can't find a place to debug a production build. Mplab8 could have done it I think.

    Erik Friesen
    #6
    friesen
    Super Member
    • Total Posts : 1724
    • Reward points : 0
    • Joined: 2008/05/08 05:23:35
    • Location: Indiana, USA
    • Status: online
    Re: PIC24F debugging fun 2017/09/11 15:59:42 (permalink)
    0
    So far, I have narrowed it to this current piece of code
     
    1415: void MoveToScrollPrintPoint(const MenuGroup * Item) {
    0067E0 FA0006 LNK #0x6
     
    I don't know enough about 24 asm to know, but somehow this stack frame pointer causes the crash.

    Erik Friesen
    #7
    dan1138
    Super Member
    • Total Posts : 2599
    • Reward points : 0
    • Joined: 2007/02/21 23:04:16
    • Location: 0
    • Status: offline
    Re: PIC24F debugging fun 2017/09/11 17:00:37 (permalink)
    3 (1)
    The behavior you have described seems like it could be caused by an overrun of an array boundary or using a bad pointer to a function.
    #8
    friesen
    Super Member
    • Total Posts : 1724
    • Reward points : 0
    • Joined: 2008/05/08 05:23:35
    • Location: Indiana, USA
    • Status: online
    Re: PIC24F debugging fun 2017/09/11 17:14:26 (permalink)
    0
    If I don't comment out geterrloc from the address trap I get a trap error reset.

    I did a port of a 32 bit menu system, but is it wrong to assume that there should be no problems as long as stuff is word aligned? Or are there cases where complex arrays of structs need to be 32 bit aligned?

    It's a bit frustrating that this behavior only happens when not in debug.

    Erik Friesen
    #9
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 1473
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: PIC24F debugging fun 2017/09/11 17:23:41 (permalink)
    3 (1)
    Stack frame was not big enough.  Memory outside the stack frame got modified.
     
    If you have access to the source.  Looks like it is set for 3 integers, maybe it is not enough.
    Try doubling it, [LNK #12], if that doesn't work, try LNK #100
     
    Possible after multiple calls it is not getting unlinked and the stack is full.
    (Buggy code like in MPlab X)
     
    void MoveToScrollPrintPoint(const MenuGroup * Item)  Microchip code?
     

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #10
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 1473
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: PIC24F debugging fun 2017/09/11 17:30:53 (permalink)
    3 (1)
    As long as there are no single bytes then alignment won't be a problem.
     
    That depends on that function, if it is a menu, shouldn't it be **Item.
    Like multi-dimensional?  Pointer to pointers.
     
    Address trap, trying to access an odd address.
    Alignment bug.
     
    You need to show some code
    post edited by Gort2015 - 2017/09/11 17:32:56

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #11
    friesen
    Super Member
    • Total Posts : 1724
    • Reward points : 0
    • Joined: 2008/05/08 05:23:35
    • Location: Indiana, USA
    • Status: online
    Re: PIC24F debugging fun 2017/09/11 17:31:49 (permalink)
    3 (1)
    Well, that is the dissassembly. It is all my code, all written in c. I assume that is where it is breaking, because my persistent tracking variable gets set right before the function call, and never gets the new value set on function entry. I suppose the stack has been trashed somewhere, unless it is some cross word array access I haven't perceived. As stated, geterrloc re traps.

    Erik Friesen
    #12
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 1473
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: PIC24F debugging fun 2017/09/11 17:36:51 (permalink)
    0
    There's different ways to call a function.
    By stack or by setting safe registers. (w0-w7)
     
    geterrloc - what's that?

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #13
    friesen
    Super Member
    • Total Posts : 1724
    • Reward points : 0
    • Joined: 2008/05/08 05:23:35
    • Location: Indiana, USA
    • Status: online
    Re: PIC24F debugging fun 2017/09/11 17:43:20 (permalink)
    0
    Header file
    typedef struct {
        unsigned char x;
        unsigned char y;
        unsigned char PosX : 6;
        unsigned char PosY : 6;
        unsigned char Font : 4;
    } _point;

    typedef struct {
        char * Index; //"1.0" or "12.4"
        void * Position; //either "xy" or _point * ptr
        void * ItemPtr; //either "Caption" or &Var
        void (*CustomBranchPtr)(void); //for leaving the menu system
        char * Options;
        unsigned char Sel_X : 4; //position to highlight
        unsigned char Sel_Y : 6; //position to highlight
        unsigned char MenuType : 6; //graphics, numbers, text, etc.
    } MenuGroup;

     
    Called like
     
    void PrintMenuItems(const MenuGroup ** List) {
      int a = 0;
      MoveToScrollPrintPoint(List[a]);
    }//Very shortened, only for showing pointer calling

    void MoveToScrollPrintPoint(const MenuGroup * Item) {
        _point T = FindPrintOptionFromList(Item->Sel_X, Item->Sel_Y - MyScrollPositionOffset, (_point*) Item->Position);
        MoveTo(T.x, T.y);
        setfont(T.Font);
    }


    Erik Friesen
    #14
    friesen
    Super Member
    • Total Posts : 1724
    • Reward points : 0
    • Joined: 2008/05/08 05:23:35
    • Location: Indiana, USA
    • Status: online
    Re: PIC24F debugging fun 2017/09/11 17:47:01 (permalink)
    0
    Really though here, this problem moves around on me, depending on alignment or something.  If I compile with a different memory model, this problem goes away, or at least moves to something waiting to bite me when I send it out the door.

    Erik Friesen
    #15
    friesen
    Super Member
    • Total Posts : 1724
    • Reward points : 0
    • Joined: 2008/05/08 05:23:35
    • Location: Indiana, USA
    • Status: online
    Re: PIC24F debugging fun 2017/09/11 17:49:01 (permalink)
    3 (1)
    geterrloc.s is the standard include to find out where the address trap happened that comes with the microchip traps.c code.

    Erik Friesen
    #16
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 1473
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: PIC24F debugging fun 2017/09/11 17:53:53 (permalink)
    0
    On struct _point add a padding byte or change to integer since position maybe more that 255.
    That could be the trap error.
     
    void (*CustomBranchPtr)(void); //for leaving the menu system

    Do you call that or jump?

    When defining types or structs it is good practice to append _t

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #17
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 1473
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: PIC24F debugging fun 2017/09/11 18:01:50 (permalink)
    3 (1)
    Never used that (geterrloc.s), I just print to the console from the trap and lock it.
    When debugging, a global variable can be incremented and printed from the trap.

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #18
    friesen
    Super Member
    • Total Posts : 1724
    • Reward points : 0
    • Joined: 2008/05/08 05:23:35
    • Location: Indiana, USA
    • Status: online
    Re: PIC24F debugging fun 2017/09/11 18:05:29 (permalink)
    0
    Custombranchptr gets called, for custom display stuff. _points are const arrays of menu points and corresponding locations, or posx and posy which are the cursor locations, and are never more than 6 bits.

    I originally layed this out for the pic32 and made sure stuff got aligned to 32 bits. The pic24 is a bit different, I also have to remember memory model stuff, etc.

    Erik Friesen
    #19
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 1473
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: PIC24F debugging fun 2017/09/11 18:19:11 (permalink)
    0
    FindPrintOptionFromList(Item->Sel_X, Item->Sel_Y - MyScrollPosition

    Could cause a bug if FindPrintOptionFromList expects integers.

    Best to change _point to integers.
    And pointing to unsigned char PosX : 6;

    You can't point to bit positions.

    It's not worth the hassle to try and save a few bytes.
    unsigned char PosX : 6;
    unsigned char PosY : 6;
    unsigned char Font : 4;

    TO

    unsigned int PosX;
    unsigned int PosY;
    unsigned int Font;


    post edited by Gort2015 - 2017/09/11 18:21:06

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #20
    Page: 123 > Showing page 1 of 3
    Jump to:
    © 2017 APG vNext Commercial Version 4.5