Skip to content

Commit

Permalink
gdb/fs: handle special inode of epoll, eventfd etc.
Browse files Browse the repository at this point in the history
Those inodes have no name, handle them so the path can correctly show.
Add FILEP output so we can investigate furthure manually.
Change OFLAGS to hex output and increase word space.

E.g.
(gdb) fdinfo -p 120
PID: 120
FD  FILEP       OFLAGS      POS       PATH                                            BACKTRACE
0   0x40807f08  0x3         0         /dev/console
1   0x40807f30  0x3         0         /dev/console
2   0x40807f58  0x3         0         /dev/console
3   0x40807f80  0x400       0         epoll
4   0x40807fa8  0x443       0         eventfd
5   0x40807fd0  0x403       0         sock
6   0x40807ff8  0x403       0         sock
7   0x40808020  0x403       0         sock
8   0x40892520  0x403       0         sock
9   0x40892548  0x403       0         sock
10  0x40892570  0x403       0         sock
11  0x40892598  0x403       0         sock
12  0x408925c0  0x403       0         sock
13  0x408925e8  0x403       0         sock
14  0x40892610  0x403       0         sock
15  0x40892638  0x403       0         sock
16  0x40942a20  0x403       0         sock

Signed-off-by: xuxingliang <[email protected]>
  • Loading branch information
XuNeo authored and xiaoxiang781216 committed Nov 24, 2024
1 parent 5b43a8c commit 03a38fa
Showing 1 changed file with 41 additions and 6 deletions.
47 changes: 41 additions & 6 deletions tools/gdb/nuttxgdb/fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
)
CONFIG_FS_SHMFS = utils.get_symbol_value("CONFIG_FS_SHMFS")

g_special_inodes = {} # Map of the special inodes including epoll, inotify, etc.


class InodeType(enum.Enum):
# define FSNODEFLAG_TYPE_PSEUDODIR 0x00000000 /* Pseudo dir (default) */
Expand Down Expand Up @@ -70,6 +72,34 @@ class InodeType(enum.Enum):
def get_inode_name(inode):
if not inode:
return ""

def special_inode_name(inode):
global g_special_inodes
if not g_special_inodes:
g_special_inodes = {}
for special in (
"perf",
"timerfd",
"signalfd",
"dir",
"inotify",
"epoll",
"eventfd",
"sock",
):
value = utils.gdb_eval_or_none(f"g_{special}_inode")
if value:
g_special_inodes[special] = value.address

for name, value in g_special_inodes.items():
if value == inode:
return name

return None

if name := special_inode_name(inode):
return name

ptr = inode["i_name"].cast(gdb.lookup_type("char").pointer())
return ptr.string()

Expand Down Expand Up @@ -165,16 +195,21 @@ def print_file_info(self, fd, file, formatter):
)

output.append(
formatter.format(fd, oflags, pos, path, backtrace.formatted[0])
formatter.format(
fd, hex(file.address), oflags, pos, path, backtrace.formatted[0]
)
)
output.extend(
formatter.format("", "", "", "", bt) for bt in backtrace.formatted[1:]
formatter.format("", "", "", "", "", bt)
for bt in backtrace.formatted[1:]
)
output.append("") # separate each backtrace
else:
output = [formatter.format(fd, oflags, pos, path, "")]
output = [
formatter.format(fd, hex(file.address), hex(oflags), pos, path, "")
]

gdb.write("\n".join(output))
gdb.write("\n".join(output).rstrip()) # strip trailing spaces
gdb.write("\n")

def print_fdinfo_by_tcb(self, tcb):
Expand All @@ -190,8 +225,8 @@ def print_fdinfo_by_tcb(self, tcb):

self.processed_groups.add(group)

headers = ["FD", "OFLAGS", "POS", "PATH", "BACKTRACE"]
formatter = "{:<4}{:<8}{:<6}{:<22}{:<50}"
headers = ["FD", "FILEP", "OFLAGS", "POS", "PATH", "BACKTRACE"]
formatter = "{:<4}{:<12}{:<12}{:<10}{:<48}{:<50}"
gdb.write(formatter.format(*headers) + "\n")

fd_count = 0
Expand Down

0 comments on commit 03a38fa

Please sign in to comment.