This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Segger Embedded Studio: adding thread awareness for Zephyr

"SES > File > Open nRF Connect SDK Project..." does not seem to include a thread aware script for Zephyr.  Is there a provided script for this somewhere?  If not is there a reason it isn't included?

From an earlier post, I create the script below based on the scant information I could find:

// prj.conf:
// CONFIG_THREAD_MONITOR=y
// CONFIG_THREAD_STACK_INFO=y
// CONFIG_THREAD_NAME=y

function init()
{
  Threads.setColumns("Name", "Fn", "Priority", "State", "Handle");
  Threads.setSortByNumber("Priority");
  Threads.setSortByNumber("State");
  Threads.setSortByNumber("Handle");
}

function z_thread_state_string(thread_state)
{
	switch (thread_state) {
	case 0:
		return "";
		break;
	case 0x1:
		return "dummy";
		break;
	case 0x2:
		return "pending";
		break;
	case 0x4:
		return "prestart";
		break;
	case 0x8:
		return "dead";
		break;
	case 0x10:
		return "suspended";
		break;
	case 0x20:
		return "aborting";
		break;
	case 0x40:
		return "aborted in ISR";
		break;
	case 0x80:
		return "queued";
		break;
	}
	return "unknown";
}

function update()
{
  Threads.clear();
  var z_thread = Debug.evaluate("_kernel.threads");
  var count = 0;
  while (z_thread && count < 20) 
  {
    var td = Debug.evaluate("*(k_thread*)"+z_thread);
    var fn = Debug.evaluate("*((k_thread*)"+z_thread+")->entry.pEntry");
    var name = Debug.evaluate("(char *)((k_thread*)"+z_thread+")->name)");
    var state = z_thread_state_string(td.base.thread_state)
    Threads.add(name, fn, td.base.prio, state, "0x"+z_thread.toString(16), z_thread);
    z_thread = td.next_thread;
    count++;
  }
}

function getregs(x)
{
  var td = Debug.evaluate("*(k_thread*)"+x);
  var r0 = Debug.evaluate("*(int*)(((k_thread*)"+x+")->callee_saved.psp + 0)");
  var r1 = Debug.evaluate("*(int*)(((k_thread*)"+x+")->callee_saved.psp + 4)");
  var r2 = Debug.evaluate("*(int*)(((k_thread*)"+x+")->callee_saved.psp + 8)");
  var r3 = Debug.evaluate("*(int*)(((k_thread*)"+x+")->callee_saved.psp + 12)");
  var r12 = Debug.evaluate("*(int*)(((k_thread*)"+x+")->callee_saved.psp + 16)");
  var lr = Debug.evaluate("*(int*)(((k_thread*)"+x+")->callee_saved.psp + 20)");
  var pc = Debug.evaluate("*(int*)(((k_thread*)"+x+")->callee_saved.psp + 24)");
  var xpsr = Debug.evaluate("*(int*)(((k_thread*)"+x+")->callee_saved.psp + 28)");
  return [ r0, r1, r2, r3, td.callee_saved.v1, td.callee_saved.v2, td.callee_saved.v3, td.callee_saved.v4, td.callee_saved.v5, td.callee_saved.v6, td.callee_saved.v7, td.callee_saved.v8, r12, td.callee_saved.psp, lr, pc, xpsr ];
}
Parents
  • Hello, 

    I'm not sure I understand. Can you please elaborate on what you are looking for? From what I can see, this is something that is not available today.  What earlier post are you referring to?

    Thanks!

    Kind regards,
    Øyvind

  • The other post I was referring to is 

    • Case ID: 234112

    My question is: Why isn't a thread script provided for SES when importing a Zephyr application so that we can debug our Zephyr applications?  (Any real application using BLE, USB, etc, is going to use threads because those modules use threads behind the scenes.)

  • Hi, 

    Ok, I understand what you mean, but as mentioned in the ticket you are referring to, this is something Segger needs to fix. That said, please see this Twitter message from Segger. The problem is that the thread aware debugging support is added to SES v5.40, while SES Nordic Edition, supporting NCS, is at 5.34. This means that it does not support thread aware out of the box. 

    The (unofficial) solution to this is to copy the thread aware debugging script from SES v5.40(non nordic edition) to v5.34 (nordic edition). This should add thread aware debugging to your SES Nordic Edition which supports NCS, and debugging multiple .elf files i.e. mcuboot, spm, and e.g. asset tracker. 

    Let me know how that works for you. 

    Kind regards,
    Øyvind

Reply
  • Hi, 

    Ok, I understand what you mean, but as mentioned in the ticket you are referring to, this is something Segger needs to fix. That said, please see this Twitter message from Segger. The problem is that the thread aware debugging support is added to SES v5.40, while SES Nordic Edition, supporting NCS, is at 5.34. This means that it does not support thread aware out of the box. 

    The (unofficial) solution to this is to copy the thread aware debugging script from SES v5.40(non nordic edition) to v5.34 (nordic edition). This should add thread aware debugging to your SES Nordic Edition which supports NCS, and debugging multiple .elf files i.e. mcuboot, spm, and e.g. asset tracker. 

    Let me know how that works for you. 

    Kind regards,
    Øyvind

Children
Related