• AVR Freaks

[FAQ]Hard coding a software breakpoint

Author
JasonK
Moderator
  • Total Posts : 3383
  • Reward points : 0
  • Joined: 2003/11/14 09:49:40
  • Location: Microchip Technology in Arizona, USA
  • Status: offline
2009/07/08 13:29:02 (permalink)
0

Hard coding a software breakpoint

Here's a short example showing how you can hard code a software breakpoint (sdbbp) in your code using a macro.

#include <p32xxxx.h>
#include <plib.h>

#pragma config FPLLMUL = MUL_20, FPLLIDIV = DIV_2, FPLLODIV = DIV_1, FWDTEN = OFF
#pragma config POSCMOD = HS, FNOSC = PRIPLL, FPBDIV = DIV_8

#define SYS_FREQ (80000000L)

#if defined(__DEBUG)
#define debughalt() __asm__ volatile (" sdbbp 0")
#else
#define debughalt() (void)0
#endif

int main(void)
{
SYSTEMConfig(SYS_FREQ, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);
_CP0_BIC_DEBUG(_CP0_DEBUG_COUNTDM_MASK);

debughalt(); /* Break here when compiling under a Debug build configuration */

while(1);
return 0;
}


Jason Kajita
 Follow me on Twitter
http://support.microchip.com for urgent questions
#1

16 Replies Related Threads

    QKernel
    Super Member
    • Total Posts : 220
    • Reward points : 0
    • Joined: 2008/09/23 17:09:44
    • Location: Alberta Canada
    • Status: offline
    RE: Hard coding a software breakpoint 2009/07/08 22:26:48 (permalink)
    0
    Thanks Jason

    I have tried it and it works great. Another tool in our toolbox.

    Q▪Kernel The new generation RTOS
    ▪ Dual mode RTOS (PIC24, dsPIC and PIC32)
    ▪ Never disables interrupts
    ▪ Fibers, threads and lightweight threads
    Free download at www.quasarsoft.com
    #2
    Antipodean
    Super Member
    • Total Posts : 1707
    • Reward points : 0
    • Joined: 2008/12/09 10:19:08
    • Location: Didcot, United Kingdom
    • Status: offline
    RE: Hard coding a software breakpoint 2009/07/09 01:36:57 (permalink)
    0
    Can this technique be used with C30 as well? It looks to me like it should be possible, as the PIC24 I am using has unassigned interrupt vectors.

    Do not use my alias in your message body when replying, your message will disappear ...

    Alan
    #3
    JasonK
    Moderator
    • Total Posts : 3383
    • Reward points : 0
    • Joined: 2003/11/14 09:49:40
    • Location: Microchip Technology in Arizona, USA
    • Status: offline
    RE: Hard coding a software breakpoint 2009/07/09 08:34:20 (permalink)
    0
    Can this technique be used with C30 as well?

    Yes, using the MPLAB C Compiler for PIC24 and/or dsPIC, try
    __asm__ volatile (" .pword 0xDA4000");

    Jason Kajita
     Follow me on Twitter
    http://support.microchip.com for urgent questions
    #4
    jtemples
    عُضْوٌ جَدِيد
    • Total Posts : 11209
    • Reward points : 0
    • Joined: 2004/02/13 12:31:19
    • Location: Southern California
    • Status: offline
    RE: Hard coding a software breakpoint 2009/07/09 10:20:48 (permalink)
    0
    Can this be done on the PIC16 or PIC18?
    #5
    JasonK
    Moderator
    • Total Posts : 3383
    • Reward points : 0
    • Joined: 2003/11/14 09:49:40
    • Location: Microchip Technology in Arizona, USA
    • Status: offline
    RE: Hard coding a software breakpoint 2009/07/09 10:27:17 (permalink)
    0
    Haha, I guess I should have seen that coming.
    For the MPLAB C Compiler for PIC18, I use

    void halt(void)
    {
    /* {_asm HALT _endasm} */
    {_asm TRAP _endasm}
    }

    I'm not aware of anything for the PIC16 and lower devices. I'll ask around.
    post edited by JasonK - 2009/07/09 14:28:46

    Jason Kajita
     Follow me on Twitter
    http://support.microchip.com for urgent questions
    #6
    Stefan Uhlemayr
    Super Member
    • Total Posts : 4292
    • Reward points : 0
    • Joined: 2005/05/12 12:25:46
    • Location: Germany
    • Status: offline
    RE: Hard coding a software breakpoint 2009/07/09 12:43:17 (permalink)
    0
    ORIGINAL: jtemples

    Can this be done on the PIC16 or PIC18?
    I don't know how to code it in "C", but in assembler you may place a lot of breakpoints on any 8-bit-PIC (with the disadvantage of loosing one stack-level and two bytes of rom-space for every breakpoint sad), the example is for PIC18:

    BREAK_POINT
            NOP            ;place here the available hardware-breakpoint
            RETURN
    Now, you can place at any point of your code

           ...
           CALL BREAK_POINT
           ...
    After the debugger has stopped the execution at the breakpoint, you can jump back to the place, where it happens with just one single-step.

    Greetings,
    Stefan
    #7
    JasonK
    Moderator
    • Total Posts : 3383
    • Reward points : 0
    • Joined: 2003/11/14 09:49:40
    • Location: Microchip Technology in Arizona, USA
    • Status: offline
    RE: Hard coding a software breakpoint 2009/07/09 12:51:27 (permalink)
    0
    I believe that MPASM will assemble the PIC18 HALT instruction also (although I don't think I've tried it myself). You might want to give it a shot.
    post edited by JasonK - 2009/07/09 16:46:39

    Jason Kajita
     Follow me on Twitter
    http://support.microchip.com for urgent questions
    #8
    Stefan Uhlemayr
    Super Member
    • Total Posts : 4292
    • Reward points : 0
    • Joined: 2005/05/12 12:25:46
    • Location: Germany
    • Status: offline
    RE: Hard coding a software breakpoint 2009/07/09 13:06:02 (permalink)
    0
    ORIGINAL: JasonK

    I believe that MPASM will assemble the PIC18 HALT instruction also (although I don't think I've tried it myself). You might want to give it a shot. A benefit would be that software breakpoints don't skid.
    Hi Jason,

    is this HALT-instruction explained somewhere? And maybe there are more secret instructions? Smile

    Anyway, I've tried it in MPLAB v8.10 (I'm still happy with this version) with a PIC18F4680. While the assembler hasn't complained this instruction (no warning or error), the code-execution wasn't stopped with the ICD2 in debug-mode. Maybe I've done something wrong, but hardware-breakpoint was working fine...

    Greetings,
    Stefan

    EDIT: corrected the MPLAB-version, which I'm still using...
    post edited by Stefan Uhlemayr - 2009/07/10 11:57:05
    #9
    JasonK
    Moderator
    • Total Posts : 3383
    • Reward points : 0
    • Joined: 2003/11/14 09:49:40
    • Location: Microchip Technology in Arizona, USA
    • Status: offline
    RE: Hard coding a software breakpoint 2009/07/09 14:26:11 (permalink)
    0
    Oh, whoops, I gave you the wrong instruction. For PIC18 with PICkit 2/3, ICD 2/3, or REAL ICE use

    void trap (void)
    {
    {_asm TRAP _endasm}
    }

    The HALT instruction is for ICE 2000/4000 and simulator only.
    post edited by JasonK - 2009/07/09 14:27:15

    Jason Kajita
     Follow me on Twitter
    http://support.microchip.com for urgent questions
    #10
    Stefan Uhlemayr
    Super Member
    • Total Posts : 4292
    • Reward points : 0
    • Joined: 2005/05/12 12:25:46
    • Location: Germany
    • Status: offline
    RE: Hard coding a software breakpoint 2009/07/10 12:01:03 (permalink)
    0
    ORIGINAL: JasonK

    Oh, whoops, I gave you the wrong instruction. For PIC18 with PICkit 2/3, ICD 2/3, or REAL ICE use

    void trap (void)
    {
    {_asm TRAP _endasm}
    }

    The HALT instruction is for ICE 2000/4000 and simulator only.
    Thanks Jason, the TRAP-instruction works like a charm for the PIC18 (tested with same configuration as mentioned above). The pretty is, that it doesn't waste the stack-level like my "workaround" and it looks like, that there's no limit, how many breakpoints are placed. Smile

    Is there anything similar available for the PIC16-series, too (when compiling a code for the PIC16, the TRAP-instruction is interpreted to be a label)?

    Greetings,
    Stefan
    #11
    scharaku
    New Member
    • Total Posts : 6
    • Reward points : 0
    • Joined: 2010/05/04 22:55:01
    • Location: 0
    • Status: offline
    RE: Hard coding a software breakpoint 2010/05/05 02:55:06 (permalink)
    0
    Thnaks
    post edited by scharaku - 2010/05/05 03:16:52

    SCharaku
    #12
    bazrush
    Starting Member
    • Total Posts : 13
    • Reward points : 0
    • Joined: 2011/12/12 07:59:12
    • Location: 0
    • Status: offline
    Re: RE: Hard coding a software breakpoint 2013/07/01 13:05:01 (permalink)
    0
    Sorry to dredge up an old thread, and probably in the wrong bit of the forum(!), but why is the breakpoint instruction not documented in the
    16-bit MCU and DSC Programmer’s Reference Manual?  It'd have saved me about two hours trying to understand what the hell this DAxxx instruction was doing in my debug code!
     
    Surely it ought to be in there? 



    #13
    JasonK
    Moderator
    • Total Posts : 3383
    • Reward points : 0
    • Joined: 2003/11/14 09:49:40
    • Location: Microchip Technology in Arizona, USA
    • Status: offline
    RE: Hard coding a software breakpoint 2013/07/08 09:58:05 (permalink)
    +2 (2)
    Introduced in XC32 v1.21:
    Builtin function for a software breakpoint -- The __builtin_software_breakpoint() function allows you to place a software breakpoint into your source code programmatically. Use this builtin function when debugging using the MPLAB REAL ICE, MPLAB ICD3, or MPLAB X simulator for generated MIPS32r2 code. You should disable calls to this builtin function when you are not debugging. See the example below.
     
    /*
     * When __DEBUG is defined, __debug_break() resolves to an MPLAB XC32 builtin
     * function, which creates a MIPS32 software debug-breakpoint (sddbp 0) instruction.
     */
    #if defined(__DEBUG)
     #define __debug_break() __builtin_software_breakpoint()
    #else
     #define __debug_break() ((void)0)
    #endif

    int kaibab(int coconino)
    {
      int retval = 0;
      if (coconino)
        {
          __debug_break();
          retval = 1;
        }
      return retval;
    }


    Jason Kajita
     Follow me on Twitter
    http://support.microchip.com for urgent questions
    #14
    whsiung
    Super Member
    • Total Posts : 1461
    • Reward points : 0
    • Joined: 2003/11/07 12:44:35
    • Location: Malaysia
    • Status: offline
    RE: Hard coding a software breakpoint 2014/01/28 20:19:24 (permalink)
    0
    Hi Jason,
    Is there any equivalent for XC16 and XC8?
     
    Thanks & best regards,
     
    WH Tan
    #15
    QKernel
    Super Member
    • Total Posts : 220
    • Reward points : 0
    • Joined: 2008/09/23 17:09:44
    • Location: Alberta Canada
    • Status: offline
    RE: Hard coding a software breakpoint 2014/01/29 10:30:22 (permalink)
    +1 (1)
    For the PIC24 
    #define BREAKPOINT                 __asm__ __volatile__ (" .pword 0xDA4000")

    Q▪Kernel The new generation RTOS
    ▪ Dual mode RTOS (PIC24, dsPIC and PIC32)
    ▪ Never disables interrupts
    ▪ Fibers, threads and lightweight threads
    Free download at www.quasarsoft.com
    #16
    whsiung
    Super Member
    • Total Posts : 1461
    • Reward points : 0
    • Joined: 2003/11/07 12:44:35
    • Location: Malaysia
    • Status: offline
    RE: Hard coding a software breakpoint 2014/02/11 01:08:29 (permalink)
    +1 (1)
    Just find out that XC8 v1.30 supports __debug_break().  Great!
    Best regards,
     
    WH Tan
    #17
    Jump to:
    © 2019 APG vNext Commercial Version 4.5