In KDS, is there a way to view all MQX tasks' debug program stack?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

In KDS, is there a way to view all MQX tasks' debug program stack?

Jump to solution
1,984 Views
mjohn
Contributor III

In Kinetis Design Studio, I've been using MQX with multiple tasks. The Task Aware Debugger has been a very useful tool when debugging, but I am curious if it is possible to see the current program stack for all the tasks whenever I pause the debugger?

This is what I'm referring to below. I am only able to see one task's program stack.

program_stack.png

Thanks,

Matt

1 Solution
982 Views
matthewkendall
Contributor V

This has come up before, e.g.: How to view call stack which task is not actived in KDS

There isn't a solution. The answer appears to be that you can only see the stack for the currently active task. It seems KDS is not really ready for serious usage in this regard.

View solution in original post

9 Replies
982 Views
ironsean
Contributor V

This is a feature sorely missed by myself as well. I would continue using Codewarrior for this reason alone if they were continuing support for MQX and Kinetis K series with it...

983 Views
matthewkendall
Contributor V

This has come up before, e.g.: How to view call stack which task is not actived in KDS

There isn't a solution. The answer appears to be that you can only see the stack for the currently active task. It seems KDS is not really ready for serious usage in this regard.

982 Views
RadekS
NXP Employee
NXP Employee

Thank you for your note.

The true is that you get it for what you paid for.

KDS is built on open source components and therefore it is offered for free.

You can anytime create/modify your implementation of GDB server and add support for this feature.

I just discover that one of our engineers already made some modifications in OpenOCD  debugger, but this change is still not released.

For more details, you can look at: http://openocd.zylin.com/#/c/2599/

So, if you have time for debugging debugger, you could apply this patch to OpenOCD and try it.


I hope it helps you.

Have a great day,
RadekS

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

982 Views
mjohn
Contributor III

Radek, do you know if there is a way to get the program counter of a currently inactive task when debugging? Or if there is perhaps an API function call that could return this information? If I was able to simply retrieve the program counter of another task, I could find what part of code it has stopped at easily. It would help out a lot when debugging.

Thank you

Matt

0 Kudos
982 Views
matthewkendall
Contributor V

I have previously modified MQX/mqx/source/tad/tad.c so that the shell "tad stack" command includes the PC in its output. This might help you.

-- 336/tad.c Wed Mar 18 13:16:29 2015

+++ 337/tad.c Wed Mar 18 13:16:16 2015

@@ -323,7 +323,7 @@

    char_ptr                 task_name;

    printf ("\nStack Usage:\n");

-   printf ("Task   Stack Base   Stack Limit   Stack Used   %% Used   Overflow?\n");

+   printf ("Task   PC   Stack Base   Stack Limit   Stack Used   %% Used   Overflow?\n");

    size = _QUEUE_GET_SIZE(&kernel_data_ptr->TD_LIST);

@@ -352,7 +352,7 @@

       {

          percent = ((_mqx_uint_ptr)td_ptr->STACK_BASE - stack_used) * 100 / ((_mqx_uint_ptr)td_ptr->STACK_BASE - (_mqx_uint_ptr)td_ptr->STACK_LIMIT);

       }

-      printf ("%s   0x%lx   0x%lx   0x%lx   %ld %%   %s\n", task_name, td_ptr->STACK_BASE, td_ptr->STACK_LIMIT, stack_used, percent,percent>=100?"Yes":"No");

+      printf ("%s   0x%lx   0x%lx   0x%lx   0x%lx   %ld %%   %s\n", task_name, *(uint_32*)(td_ptr->STACK_PTR + 64)-1, td_ptr->STACK_BASE, td_ptr->STACK_LIMIT, stack_used, percent,percent>=100?"Yes":"No");

       size--;

       td_ptr = (TD_STRUCT_PTR)((uchar_ptr)(td_ptr->TD_LIST_INFO.NEXT) - FIELD_OFFSET(TD_STRUCT,TD_LIST_INFO));

That patch applies to MQX 4.0.1 rather than the latest, but it looks like the source hasn't changed much since then.

0 Kudos
982 Views
DavidS
NXP Employee
NXP Employee

Hi Matt,

Attached is an example I did using MQX back in 2011 to find PC of a task descriptor.  I started with the mqx/examples/lwevent project.

Hope it helps.

Regards,

David

0 Kudos
982 Views
matthewkendall
Contributor V

Hi Radek,

It is true this is a really nice feature of CodeWarrior that is not present in the open source implementations. I came across the same issue a couple of years ago when I was doing a project with FreeRTOS on an NXP Cortex-M with the LPCXpresso toolchain, which is also based on Eclipse and OpenOCD if I remember correctly. At that time I looked in to whether it would be possible to add this feature but did not have the time to get anywhere with it. If one of your engineers has been working on OpenOCD towards this goal that would be great. I will take a look.

Regards,

Matthew

0 Kudos
982 Views
mjohn
Contributor III

Thank you, I will have to try this out when I have more time.

0 Kudos
982 Views
RadekS
NXP Employee
NXP Employee

Unfortunately we are not able manage it by TAD.

This information (current program stack for all the tasks) could be obtained only by debugger who deeply know elf file and who know how data are stored on stack.

Theoretically we can read it from task stacks, however structure of information in stack is inconsistent and we do not know any fix point where we can read PC value.

Information about current program stack for all the tasks is one of CodeWarrior debugger features, however it seems that open source debuggers doesn’t offer such feature. Maybe I am wrong and there is any option, but unfortunately I do not know about it. I am sorry.

I hope it helps you.

Have a great day,
RadekS

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos