Skip to content

Commit

Permalink
gdb/dmesg: print dmesg in the correct order
Browse files Browse the repository at this point in the history
Now the dmesg output log in correct time order, from oldest to latest.
The NULL strings are also stripped, if the buffer is never get fully
filled.

Signed-off-by: xuxingliang <[email protected]>
  • Loading branch information
XuNeo authored and xiaoxiang781216 committed Nov 23, 2024
1 parent c29f939 commit 1485ecd
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions tools/gdb/nuttxgdb/dmesg.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,17 @@ def _get_buf(self):
gdb.write("RAM log not available.\n")
return None

rl_head = sysdev["rl_header"]
rl_header = sysdev["rl_header"]
rl_bufsize = sysdev["rl_bufsize"]

offset = rl_header["rl_head"] % rl_bufsize # Currently writing to this offset
tail = rl_bufsize - offset # Total size till buffer end.
rl_buffer = int(rl_header["rl_buffer"].address) # rl_buffer is a char array

inf = gdb.selected_inferior()
buf = bytes(inf.read_memory(rl_head["rl_buffer"], rl_bufsize))
buf = bytes(inf.read_memory(offset + rl_buffer, tail))
buf = buf.lstrip(b"\0") # Remove leading NULLs
buf += bytes(inf.read_memory(rl_buffer, offset))
buf = buf.replace(
b"\0", "␀".encode("utf-8")
) # NULL is valid utf-8 but not printable
Expand Down

0 comments on commit 1485ecd

Please sign in to comment.