snikeguo opened a new issue, #16409:
URL: https://github.com/apache/nuttx/issues/16409

   ### Is your feature request related to a problem? Please describe.
   
   Some firmware runs in RAM, such as external SDRAM, where breakpoint 
instructions can be used to implement an unlimited number of breakpoints.
   
   
   
   ### Describe the solution you'd like
   
   pseudocode:
   ```
   typedef uint16_t platform_bkpt_t;//armv7m bkpt is 16 bits
   struct debug_point
   {
           int type;
           platform_bkpt_t old_instruction;
          uintptr_t address;
          void *arg;
          debug_callback_t callback;
           bool is_active;
           bool is_software;
   }
   list<debug_point> debug_points;
   int up_debugpoint_add(int type, void *addr, size_t size,
           debug_callback_t callback, void *arg,bool is_software)
   {
           struct debug_point dp;
           dp.address = (uintptr_t)addr;
           dp.callback = callback;
           dp.arg = arg;
           dp.is_active = true;
           dp.is_software = is_software;
           dp.type = type;
           
           bool is_valid = false;
           ...
           
           if(is_software)
           {
                   is_valid=true;
                   memcpy(&dp.old_instruction, (void *)addr, 
sizeof(platform_bkpt_t));
           }
           else
           {
                   // Add hardware breakpoint
                   // ...
                   var 
hardware_breakpoint_count=debug_points.select(x=>x.is_software==false).Count();//get
 count of hardware breakpoints
                   if(hardware_breakpoint_count>=MAX_HARDWARE_BREAKPOINTS)
                   {
                           // Error: too many hardware breakpoints
                           is_valid=false;
                   }
           }
           if(is_valid)
           {
                   debug_points.push_back(dp);
           }
           
           return 0;
   }
   int arm_dbgmonitor(int irq, void *context, void *arg)
   {
           var pc=regs[REG_PC];
           var breakpoint=debug_points.find(x=>x.address==pc);
           if(breakpoint!=null)
           {
                   if(breakpoint.is_software)
                   {
                           // Handle software breakpoint, restore old 
instruction
                           memcpy((void *)pc, &breakpoint.old_instruction, 
sizeof(platform_bkpt_t));
                           breakpoint.callback(breakpoint.arg);
                   }
                   else
                   {
                           // Handle hardware breakpoint
                           // ...
                   }
                   arm_steppoint_match();...
                   arm_breakpoint_match()..
                   arm_watchpoint_match()...
           }
   }
   ```
   
   ### Describe alternatives you've considered
   
   _No response_
   
   ### Verification
   
   - [x] I have verified before submitting the report.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to