c - 指向结构数据时 bf561 COREB FreeRTOS 实现中的运行时错误

标签 c pointers structure runtime-error freertos

当多个函数尝试访问通常作为参数传递给函数的结构数据时,我遇到了运行时错误。

问题的第一个实例是:

signed portBASE_TYPE xQueueGenericReceive( xQueueHandle pxQueue, void * const p\

vBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking )

{

..............



if( pxQueue->uxMessagesWaiting > ( unsigned portBASE_TY\

PE ) 0 )



.......................



}

其中 pxQueue 是一个结构:

typedef xQUEUE * xQueueHandle;

与:

typedef struct QueueDefinition

{

        signed char *pcHead;                            /*< Points to the begin\

ning of the queue storage area. */

    signed char *pcTail;                            /*< Points to the byte \

at the end of the queue storage area.  Once more byte is allocated than necessa\

ry to store the queue items, this is used as a marker. */



        signed char *pcWriteTo;                         /*< Points to the free \

next place in the storage area. */

        signed char *pcReadFrom;  
                    /*< Points to the last \

place that a queued item was read from. */


        xList xTasksWaitingToSend;                              /*< List of tas\

ks that are blocked waiting to post onto this queue.  Stored in priority order.\

*/
        xList xTasksWaitingToReceive;                   /*< List of tasks that \

are blocked waiting to read from this queue.  Stored in priority order. */


        volatile unsigned portBASE_TYPE uxMessagesWaiting;/*< The number of ite\

ms currently in the queue. */
        unsigned portBASE_TYPE uxLength;                /*< The length of the q\

ueue defined as the number of items it will hold, not the number of bytes. */
        unsigned portBASE_TYPE uxItemSize;              /*< The size of each it\

ems that the queue will hold. */


        signed portBASE_TYPE xRxLock;                   /*< Stores the number o\

f items received from the queue (removed from the queue) while the queue was lo\

cked.  Set to queueUNLOCKED when the queue is not locked. */
        signed portBASE_TYPE xTxLock;                   /*< Stores the number o\

f items transmitted to the queue (added to the queue)

while the queue was locke\

d.  Set to qu.......................



}

其中 pxQueue 是一个结构:

typedef xQUEUE * xQueueHandle;

与:

typedef struct QueueDefinition

{

        signed char *pcHead;                            /*< Points to the begin\

ning of the queue storage area. */

    signed char *pcTail;                            /*< Points to the byte \

at the end of the queue storage area.  Once more byte is allocated than necessa\

ry to store the queue items, this is used as a marker. */



        signed char *pcWriteTo;                         /*< Points to the free \

next place in the storage area. */

        signed char *pcReadFrom;  
                    /*< Points to the last \

place that a queued item was read from. */


        xList xTasksWaitingToSend;                              /*< List of tas\

ks that are blocked waiting to post onto this queue.  Stored in priority order.\

*/
        xList xTasksWaitingToReceive;                   /*< List of tasks that \

are blocked waiting to read from this queue.  Stored in priority order. */


        volatile unsigned portBASE_TYPE uxMessagesWaiting;/*< The number of ite\

ms currently in the queue. */
        unsigned portBASE_TYPE uxLength;                /*< The length of the q\

ueue defined as the number of items it will hold, not the number of bytes. */
        unsigned portBASE_TYPE uxItemSize;              /*< The size of each it\

ems that the queue will hold. */


        signed portBASE_TYPE xRxLock;                   /*< Stores the number o\

f items received from the queue (removed from the queue) while the queue was lo\

cked.  Set to queueUNLOCKED when the queue is not locked. */
        signed portBASE_TYPE xTxLock;                   /*< Stores the number o\

f items transmitted to the queue (added to the queue)

while the queue was locke\

d.  Set to queueUNLOCKED when the queue is not locked. */



} xQUEUE;
eueUNLOCKED when the queue is not locked. */



} xQUEUE;

运行时错误是:

.....
COREB: start xQueueGenericReceive                                           
COREB: execption 24 addr 3c00384                                            
COREB: coreb dump stack                                                     
COREB: found fp: ff700900                                                   
COREB:  call frame 0 -12 feb055e2                                           
COREB:  call frame 0 -11 00000000                                           
COREB:  call frame 0 -9 00000000                                            
COREB:  call frame 0 -8 ff7008d0    

......

同样,我对以下函数也有同样的问题:

void vListRemove( xListItem *pxItemToRemove )

{

xList * pxList;



   pxItemToRemove->pxNext->pxPrevious = pxItemToRemove->pxPrevious;

        pxItemToRemove->pxPrevious->pxNext = pxItemToRemove->pxNext;

}

其中 pxItemToRemove->pxPrevious 可以读取,但不能读取 pxItemToRemove->pxNext->pxPrevious

它的结构是:

struct xLIST_ITEM

{

     portTickType xItemValue;                                /*< The value b\

eing listed.  In most cases this is used to sort the list in descending order. \

*/

        volatile struct xLIST_ITEM * pxNext;    /*< Pointer to the next xListIt\

em in the list. */

        volatile struct xLIST_ITEM * pxPrevious;/*< Pointer to the previous xLi\

stItem in the list. */

        void * pvOwner;                                                 /*< Poi\

nter to the object (normally a TCB) that contains the list item.  There is ther\

efore a two way link between the object containing the list item and the list i\

tem itself. */

        void * pvContainer;                                             /*< Poi\

nter to the list in which this list item is placed (if any). */

};

typedef struct xLIST_ITEM xListItem;            /* For some reason lint wants t\

his as two separate definitions. */

运行时错误是:

COREB: got to vTaskDelete                                                   
COREB: pxTCB GLI prev: a5a5a5a5                                             
COREB: sent to list: 3d02004                                                
COREB: list_rem px prev: a5a5a5a5                                           
COREB: execption 24 addr 3c05444                                            
COREB: coreb dump stack                                                     
COREB: found fp: ff7008fc                                                   
COREB:  call frame 0 -12 feb055e2                                           
COREB:  call frame 0 -11 00000000                                           
COREB:  call frame 0 -9 00000000                                            
COREB:  call frame 0 -8 ff7008cc                                            
COREB:  call frame 0 -7 ff700ff4    

提前谢谢您。

威廉

<小时/>

使用 gdb 进一步调试我得到了 pxQueue:

p/x *pxQueue

$9 = {pcHead = 0xadadadad, pcTail = 0xadadadad, pcWriteTo = 0xadadadad,

  pcReadFrom = 0xadadadad, xTasksWaitingToSend = {

    uxNumberOfItems = 0xadadadad, pxIndex = 0xadadadad, xListEnd = {

      xItemValue = 0xadad, pxNext = 0xadadadad, pxPrevious = 0xadadadad}},

  xTasksWaitingToReceive = {uxNumberOfItems = 0xadadadad,

    pxIndex = 0xadadadad, xListEnd = {xItemValue = 0xadad,

      pxNext = 0xadadadad, pxPrevious = 0xadadadad}},

  uxMessagesWaiting = 0xadadadad, uxLength = 0xadadadad,

  uxItemSize = 0xadadadad, xRxLock = 0xadadadad, xTxLock = 0xadadadad}

真的很奇怪,结构体的所有参数都有相同的值:0xadadadad

当我进一步调试并查看创建队列函数中作为队列对象的信号量创建时,我得到了正常值:

 p *pxNewQueue

$7 = {pcHead = 0x3d17000 "", pcTail = 0x3d17000 "", pcWriteTo = 0x3d17000 "", 

  pcReadFrom = 0x3d17000 "", xTasksWaitingToSend = {uxNumberOfItems = 0, 

    pxIndex = 0x3d16018, xListEnd = {xItemValue = 65535, pxNext = 0x3d16018, 

      pxPrevious = 0x3d16018}}, xTasksWaitingToReceive = {uxNumberOfItems = 0, 

    pxIndex = 0x3d1602c, xListEnd = {xItemValue = 65535, pxNext = 0x3d1602c, 

      pxPrevious = 0x3d1602c}}, uxMessagesWaiting = 0, uxLength = 1, 

  uxItemSize = 0, xRxLock = -1, xTxLock = -1}

谢谢

威廉

最佳答案

您想做什么以及如何做。什么是 COREB?

您发布的代码片段中的函数是否未根据官方 FreeRTOS 代码进行修改?代码通常被编译并链接到可执行文件中,因此您不会收到任何此类运行时错误。如果出现任何问题,您只会收到编译/链接错误。如果您遇到运行时错误,那么您是否尝试解释代码而不是编译它?

关于c - 指向结构数据时 bf561 COREB FreeRTOS 实现中的运行时错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9169534/

相关文章:

c - 如何将变量的值组合成 C 中的字符串

c - 我在哪里可以获得 OpenGL 图形头文件?

c - 为什么这个 NodeJS 比原生 C 快 2 倍?

c - 使用结构指针的内存分配问题

c - 如何返回一个指向完整数组的指针,也就是 int(*)[] 到主函数

java - Android 文件夹结构(类,...)

c - 为什么 C 库链接顺序只在某些系统上很重要?

c++ - 搜索对象指针 vector

NGINX 将请求重写到 root 之外的文件

c中字符串与字符数组的比较