Skip to content

tools/trap: Fix TCB log parsing and detect semaphore circular waits - #7676

Open
namanjain7 wants to merge 2 commits into
Samsung:masterfrom
namanjain7:trap_fix
Open

namanjain7 wants to merge 2 commits into
Samsung:masterfrom
namanjain7:trap_fix

Conversation

@namanjain7

Copy link
Copy Markdown
Contributor

This PR fixes TRAP’s asserted TCB parsing for the current log format, including flag decoding and syscall address resolution. It also adds semaphore log analysis to report waiter–holder relationships and identify possible circular waits.

I’ll address the other issues in a follow-up PR, currently working on those.

The PR is verified on rtl8730e and bk7239n.

Both below examples use the same BK7239N log.

Section Before After
TCB info t. Asserted TCB info:

No fields printed.
t. Asserted TCB info:

PID: 20
Name: hello
CPU: 0
Priority: 100
TCB address: 0x70028490
State: Running
Flags: 32 - User Task - Round Robin
Lock count: 0
Timeslice: 10
Waitdog: 0
WaitSem: 0
MsgwaitQ: 0
Sigdeliver: 0
Nsyscalls: 1
Syscall 0: up_assert
Semaphore info No semaphore section printed. Semaphore information:
Count: negative = number of waiters; zero or positive = available count
Flags: 2 = initialized; 6 = initialized, signaling; 7 = priority inheritance disabled, initialized, signaling

Possible circular waits:
Cycle group 1: PIDs 21, 22
PID 21 waits on 0x70455754 (count: -1, flags: 2) held by PID 22 (refs 1)
PID 22 waits on 0x70455748 (count: -1, flags: 2) held by PID 21 (refs 1)

Other semaphore relationships:
PID 3 waits on 0x70026460 (count: -1, flags: 6)
PID 4 waits on 0x7000f320 (count: -1, flags: 6)
PID 8 waits on 0x38047724 (count: -1, flags: 7)
PID 9 waits on 0x70004c5c (count: -1, flags: 6)
PID 17 waits on 0x704d8cf4 (count: -1, flags: 7)
PID 18 waits on 0x704da4ec (count: -1, flags: 7)
PID 19 waits on 0x704db794 (count: -1, flags: 7)

Warning: Some waiters have no recorded holder; circular waits may be missed.

Parse application text ranges from the loading location section in one
pass and compare addresses numerically. Resolve saved syscall return
addresses using the appropriate XIP or non-XIP address.

Recognize the current Task TCB info heading and decode thread type and
scheduling policy using their masks, including zero-valued fields.

Example raw log:

  Loading location information
  ===========================================================
  elf_show_all_bin_section_addr: [common] Text Addr : 0x70400020, Text Size : 227296
  elf_show_all_bin_section_addr: [app1] Text Addr : 0x706c8a20, Text Size : 96
  elf_show_all_bin_section_addr: [app2] Text Addr : 0x704d4740, Text Size : 96

  Task TCB info
  ===========================================================
  task_show_tcbinfo: PID         : 20
  task_show_tcbinfo: Name        : hello
  task_show_tcbinfo: CPU         : 0
  task_show_tcbinfo: Priority    : 100
  task_show_tcbinfo: TCB address : 0x70028490
  task_show_tcbinfo: State       : 4
  task_show_tcbinfo: Flags       : 32
  task_show_tcbinfo: Lock count  : 0
  task_show_tcbinfo: Timeslice   : 10
  task_show_tcbinfo: Waitdog     : 0
  task_show_tcbinfo: WaitSem     : 0
  task_show_tcbinfo: MsgwaitQ    : 0
  task_show_tcbinfo: Sigdeliver  : 0
  task_show_tcbinfo: Nsyscalls   : 1
  task_show_tcbinfo: Syscall 0   : 0x70426bca

Corresponding TRAP output:

  Number of binaries          : 4 [kernel + apps]
  "kernel" elf_file           : ../../../build/output/bin/tinyara.axf
  "common" elf_file           : ../../../build/output/bin/common_dbg
  "app1" elf_file             : ../../../build/output/bin/app1_dbg
  "app2" elf_file             : ../../../build/output/bin/app2_dbg

  t. Asserted TCB info:

   PID         : 20
   Name        : hello
   CPU         : 0
   Priority    : 100
   TCB address : 0x70028490
   State       : Running
   Flags       : 32        - User Task     - Round Robin
   Lock count  : 0
   Timeslice   : 10
   Waitdog     : 0
   WaitSem     : 0
   MsgwaitQ    : 0
   Sigdeliver  : 0
   Nsyscalls   : 1
   Syscall 0   : up_assert
Parse the Semaphore info section of assertion logs and display
semaphore waiters, holders, counts and decoded flags.

Identify possible circular waits from recorded waiter-holder
relationships and report when missing or truncated information may
limit the analysis.

Below is os log For BK7239N:

===========================================================
Semaphore info
===========================================================
W <waiter> <sem>(<count>,<flags>) [H <holder>(<refs>)]
H <holder>(<refs>) <sem>(<count>,<flags>)
===========================================================
W 3 0x70026460(-1,6)
W 4 0x7000f320(-1,6)
W 8 0x38047724(-1,7)
W 9 0x70004c5c(-1,6)
W 17 0x704d8cf4(-1,7)
W 18 0x704da4ec(-1,7)
W 19 0x704db794(-1,7)
W 21 0x70455754(-1,2) H 22(1)
W 22 0x70455748(-1,2) H 21(1)

Below is TRAP output of Semaphore Information:

Semaphore information:
  Count: negative = number of waiters; zero or positive = available count
  Flags in this log:
    2 = initialized
    6 = initialized, signaling
    7 = priority inheritance disabled, initialized, signaling
  Possible circular waits:
    Cycle group 1: PIDs 21, 22
      PID 21 waits on 0x70455754 (count: -1, flags: 2) held by PID 22 (refs 1)
      PID 22 waits on 0x70455748 (count: -1, flags: 2) held by PID 21 (refs 1)
  Other semaphore relationships:
    PID 3 waits on 0x70026460 (count: -1, flags: 6)
    PID 4 waits on 0x7000f320 (count: -1, flags: 6)
    PID 8 waits on 0x38047724 (count: -1, flags: 7)
    PID 9 waits on 0x70004c5c (count: -1, flags: 6)
    PID 17 waits on 0x704d8cf4 (count: -1, flags: 7)
    PID 18 waits on 0x704da4ec (count: -1, flags: 7)
    PID 19 waits on 0x704db794 (count: -1, flags: 7)
  Warning: Some waiters have no recorded holder; circular waits may be missed.
@namanjain7 namanjain7 changed the title Trap fix tools/trap: Fix TCB log parsing and detect semaphore circular waits Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant