硬汉嵌入式论坛

 找回密码
 立即注册
查看: 1038|回复: 11
收起左侧

[RTOS Trace] H7-TOOL的FreeRTOS Trace功能,仅差一个关键变量的检索差不多就完成了

[复制链接]

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106757
QQ
发表于 2023-1-11 00:59:38 | 显示全部楼层 |阅读模式

由于FreeRTOS所有对象创建基本都是动态内存管理方式(当然新版很多也支持静态方式),所以检索起来比较麻烦。

特别是这个条件编译比较多的TCB任务控制块结构体定义,其中有一个统计任务执行时间的成员,这个最不容易获取,因为前面有好几个宏定义控制。

如果是程序主动输出,那就简单很多。但我们这里需要被动检索,这就麻烦很多了

[C] 纯文本查看 复制代码
/*
 * Task control block.  A task control block (TCB) is allocated for each task,
 * and stores task state information, including a pointer to the task's context
 * (the task's run time environment, including register values)
 */
typedef struct tskTaskControlBlock                         /* The old naming convention is used to prevent breaking kernel aware debuggers. */
{
        volatile StackType_t        *pxTopOfStack;        /*< Points to the location of the last item placed on the tasks stack.  THIS MUST BE THE FIRST MEMBER OF THE TCB STRUCT. */

        #if ( portUSING_MPU_WRAPPERS == 1 )
                xMPU_SETTINGS        xMPUSettings;                /*< The MPU settings are defined as part of the port layer.  THIS MUST BE THE SECOND MEMBER OF THE TCB STRUCT. */
        #endif

        ListItem_t                        xStateListItem;        /*< The list that the state list item of a task is reference from denotes the state of that task (Ready, Blocked, Suspended ). */
        ListItem_t                        xEventListItem;                /*< Used to reference a task from an event list. */
        UBaseType_t                        uxPriority;                        /*< The priority of the task.  0 is the lowest priority. */
        StackType_t                        *pxStack;                        /*< Points to the start of the stack. */
        char                                pcTaskName[ configMAX_TASK_NAME_LEN ];/*< Descriptive name given to the task when created.  Facilitates debugging only. */ /*lint !e971 Unqualified char types are allowed for strings and single characters only. */

        #if ( ( portSTACK_GROWTH > 0 ) || ( configRECORD_STACK_HIGH_ADDRESS == 1 ) )
                StackType_t                *pxEndOfStack;                /*< Points to the highest valid address for the stack. */
        #endif

        #if ( portCRITICAL_NESTING_IN_TCB == 1 )
                UBaseType_t                uxCriticalNesting;        /*< Holds the critical section nesting depth for ports that do not maintain their own count in the port layer. */
        #endif

        #if ( configUSE_TRACE_FACILITY == 1 )
                UBaseType_t                uxTCBNumber;                /*< Stores a number that increments each time a TCB is created.  It allows debuggers to determine when a task has been deleted and then recreated. */
                UBaseType_t                uxTaskNumber;                /*< Stores a number specifically for use by third party trace code. */
        #endif

        #if ( configUSE_MUTEXES == 1 )
                UBaseType_t                uxBasePriority;                /*< The priority last assigned to the task - used by the priority inheritance mechanism. */
                UBaseType_t                uxMutexesHeld;
        #endif

        #if ( configUSE_APPLICATION_TASK_TAG == 1 )
                TaskHookFunction_t pxTaskTag;
        #endif

        #if( configNUM_THREAD_LOCAL_STORAGE_POINTERS > 0 )
                void                        *pvThreadLocalStoragePointers[ configNUM_THREAD_LOCAL_STORAGE_POINTERS ];
        #endif

        #if( configGENERATE_RUN_TIME_STATS == 1 )
                uint32_t                ulRunTimeCounter;        /*< Stores the amount of time the task has spent in the Running state. */
        #endif

        #if ( configUSE_NEWLIB_REENTRANT == 1 )
                /* Allocate a Newlib reent structure that is specific to this task.
                Note Newlib support has been included by popular demand, but is not
                used by the FreeRTOS maintainers themselves.  FreeRTOS is not
                responsible for resulting newlib operation.  User must be familiar with
                newlib and must provide system-wide implementations of the necessary
                stubs. Be warned that (at the time of writing) the current newlib design
                implements a system-wide malloc() that must be provided with locks. */
                struct        _reent xNewLib_reent;
        #endif

        #if( configUSE_TASK_NOTIFICATIONS == 1 )
                volatile uint32_t ulNotifiedValue;
                volatile uint8_t ucNotifyState;
        #endif

        /* See the comments in FreeRTOS.h with the definition of
        tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE. */
        #if( tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE != 0 ) /*lint !e731 !e9029 Macro has been consolidated for readability reasons. */
                uint8_t        ucStaticallyAllocated;                 /*< Set to pdTRUE if the task is a statically allocated to ensure no attempt is made to free the memory. */
        #endif

        #if( INCLUDE_xTaskAbortDelay == 1 )
                uint8_t ucDelayAborted;
        #endif

        #if( configUSE_POSIX_ERRNO == 1 )
                int iTaskErrno;
        #endif

} tskTCB;


回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106757
QQ
 楼主| 发表于 2023-1-11 01:08:53 | 显示全部楼层
image.png
回复

使用道具 举报

19

主题

234

回帖

291

积分

高级会员

积分
291
发表于 2023-1-11 08:13:48 | 显示全部楼层
能不能通过map文件找到
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106757
QQ
 楼主| 发表于 2023-1-11 09:16:15 | 显示全部楼层
tovinz 发表于 2023-1-11 08:13
能不能通过map文件找到

由于是动态内存管理,他们没有TCB方式定义的变量,全是动态内存申请的,所以搜不到。
回复

使用道具 举报

8

主题

155

回帖

179

积分

初级会员

H7 TOOL 大法好!

积分
179
发表于 2023-1-11 10:04:23 | 显示全部楼层
有一说一 , 个人觉得 ucos的代码风格比Freertos要好很多 , 而且源码易懂 , 文件名命名也比较好  
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106757
QQ
 楼主| 发表于 2023-1-11 10:07:26 | 显示全部楼层
312456990 发表于 2023-1-11 10:04
有一说一 , 个人觉得 ucos的代码风格比Freertos要好很多 , 而且源码易懂 , 文件名命名也比较好

是的,FreeRTOS的源码不适合阅读,可读性略差。
回复

使用道具 举报

23

主题

1406

回帖

1475

积分

至尊会员

积分
1475
发表于 2023-1-11 15:17:35 | 显示全部楼层
这个得检索宏定义有效性来识别了
代码不规范,亲人两行泪!
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106757
QQ
 楼主| 发表于 2023-1-12 01:28:01 | 显示全部楼层
missfox 发表于 2023-1-11 15:17
这个得检索宏定义有效性来识别了


这个思路,AC6需要用户添加一个参数才行。得再考虑下

H7-TOOL的RTOS Trace操作MDK AC5和MDK AC6的宏定义异同
https://www.armbbs.cn/forum.php? ... d=117118&fromuid=58
(出处: 硬汉嵌入式论坛)


回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106757
QQ
 楼主| 发表于 2023-1-16 10:37:09 | 显示全部楼层
实践证明通过各种方案检索这个变量,很难锁定偏移。得换个思路试试了。
回复

使用道具 举报

19

主题

234

回帖

291

积分

高级会员

积分
291
发表于 2023-1-16 10:57:12 | 显示全部楼层
能不能定位到动态创建函数,比如在动态分配的时候会返回分配的内存地址, 再去读那个内存地址的内容
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106757
QQ
 楼主| 发表于 2023-1-16 11:41:43 | 显示全部楼层
tovinz 发表于 2023-1-16 10:57
能不能定位到动态创建函数,比如在动态分配的时候会返回分配的内存地址, 再去读那个内存地址的内容

有个函数,不过得需要用户同时开启使用空闲任务的句柄宏定义才行
[C] 纯文本查看 复制代码
#if( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( INCLUDE_xTaskGetIdleTaskHandle == 1 ) )
	TickType_t xTaskGetIdleRunTimeCounter( void )
	{
		return xIdleTaskHandle->ulRunTimeCounter;
	}
#endif

回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106757
QQ
 楼主| 发表于 2023-1-17 00:37:34 | 显示全部楼层
已经找到解决办法,就是检索略微满分
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2024-5-5 00:21 , Processed in 0.190329 second(s), 28 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表