Skip to contentSkip to conversation

scripts:gdb: Add few structs in gdb scripts

PATCH Superseded Ritesh Harjani 2 participants 7 messages Aug 18, 2020 GDB kernel debugging helper scripts

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover scripts:gdb: Add few structs in gdb scripts

I was using these structs info internally in my gdb scripts. So sending it out for merge to upstream.

Ritesh Harjani (2):
proc: Add struct mount & struct super_block addr in lx-mounts command
tasks: Add task_struct addr for lx-ps cmd

 scripts/gdb/linux/lists.py | 43 ++++++++++++++++++++++++++++++++++++++
 scripts/gdb/linux/proc.py  | 15 +++++++------
 scripts/gdb/linux/tasks.py |  9 ++++----
 3 files changed, 12 insertions(+), 12 deletions(-)
Signature · 1 line
2.25.4
#1 lore raw

PATCH 1/2 proc: Add struct mount & struct super_block addr in lx-mounts command

This is many times found useful while debugging some FS related issue.

<e.g. output>
mount super_block fstype devname pathname options
0xffff888a0bfa4b40 0xffff888a0bfc1000 rootfs none / rw 0 0
0xffff888a02c065c0 0xffff8889fcf65000 ext4 /dev/root / rw ,relatime 0 0 0xffff8889fc8cc040 0xffff888a0bb51000 devtmpfs devtmpfs /dev rw ,relatime 0 0

---
 scripts/gdb/linux/proc.py | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
scripts/gdb/linux/proc.py +7 -8
index 6a56bba233a9..c16fab981bdd 100644
@@ -167,6 +167,9 @@ values of that process namespace"""
         if not namespace:
             raise gdb.GdbError("No namespace for current process")
 
+        gdb.write("{:^18} {:^15} {:>9} {} {} options\n".format(
+                  "mount", "super_block", "fstype", "devname", "pathname"))
+
         for vfs in lists.list_for_each_entry(namespace['list'],
                                              mount_ptr_type, "mnt_list"):
             devname = vfs['mnt_devname'].string()
@@ -190,14 +193,10 @@ values of that process namespace"""
             m_flags = int(vfs['mnt']['mnt_flags'])
             rd = "ro" if (s_flags & constants.LX_SB_RDONLY) else "rw"
 
-            gdb.write(
-                "{} {} {} {}{}{} 0 0\n"
-                .format(devname,
-                        pathname,
-                        fstype,
-                        rd,
-                        info_opts(FS_INFO, s_flags),
-                        info_opts(MNT_INFO, m_flags)))
+            gdb.write("{} {} {} {} {} {} {} {} 0 0\n".format(
+                      vfs.format_string(), superblock.format_string(), fstype,
+                      devname, pathname, rd, info_opts(FS_INFO, s_flags),
+                      info_opts(MNT_INFO, m_flags)))
 
 
 LxMounts()
Signature · 1 line
2.25.4
maintainer
#2 lore raw

Re: [PATCH 1/2] proc: Add struct mount & struct super_block addr in lx-mounts command

Quoted 33 lines · Ritesh Harjani

This is many times found useful while debugging some FS related issue.

<e.g. output>
mount super_block fstype devname pathname options
0xffff888a0bfa4b40 0xffff888a0bfc1000 rootfs none / rw 0 0
0xffff888a02c065c0 0xffff8889fcf65000 ext4 /dev/root / rw ,relatime 0 0 0xffff8889fc8cc040 0xffff888a0bb51000 devtmpfs devtmpfs /dev rw ,relatime 0 0

---
 scripts/gdb/linux/proc.py | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
scripts/gdb/linux/proc.py +3 -2
index 6a56bba233a9..c16fab981bdd 100644
@@ -167,6 +167,9 @@ values of that process namespace"""
         if not namespace:
             raise gdb.GdbError("No namespace for current process")
 
+        gdb.write("{:^18} {:^15} {:>9} {} {} options\n".format(
+                  "mount", "super_block", "fstype", "devname", "pathname"))
+
         for vfs in lists.list_for_each_entry(namespace['list'],
                                              mount_ptr_type, "mnt_list"):
             devname = vfs['mnt_devname'].string()
@@ -190,14 +193,10 @@ values of that process namespace"""
             m_flags = int(vfs['mnt']['mnt_flags'])
             rd = "ro" if (s_flags & constants.LX_SB_RDONLY) else "rw"
 
-            gdb.write(
-                "{} {} {} {}{}{} 0 0\n"

scripts/gdb/linux/proc.py values of that process namespace""" · line 199

Quoted 10 lines
scripts/gdb/linux/proc.py +4 -6
-                .format(devname,
-                        pathname,
-                        fstype,
-                        rd,
-                        info_opts(FS_INFO, s_flags),
-                        info_opts(MNT_INFO, m_flags)))
+            gdb.write("{} {} {} {} {} {} {} {} 0 0\n".format(
+                      vfs.format_string(), superblock.format_string(), fstype,
+                      devname, pathname, rd, info_opts(FS_INFO, s_flags),
+                      info_opts(MNT_INFO, m_flags)))

The last three format elements should not be space-separated. The effect can even be seen in your example above.

Jan

Quoted 4 lines
scripts/gdb/linux/proc.py +0 -0
 LxMounts()
 
Signature · 2 lines
Siemens AG, Corporate Technology, CT RDA IOT SES-DE
Corporate Competence Center Embedded Linux
#3 lore raw

Re: [PATCH 1/2] proc: Add struct mount & struct super_block addr in lx-mounts command

Quoted 32 lines · Jan Kiszka
Quoted 31 lines · Ritesh Harjani

This is many times found useful while debugging some FS related issue.

<e.g. output>
mount super_block fstype devname pathname options
0xffff888a0bfa4b40 0xffff888a0bfc1000 rootfs none / rw 0 0
0xffff888a02c065c0 0xffff8889fcf65000 ext4 /dev/root / rw ,relatime 0 0 0xffff8889fc8cc040 0xffff888a0bb51000 devtmpfs devtmpfs /dev rw ,relatime 0 0

---
  scripts/gdb/linux/proc.py | 15 +++++++--------
  1 file changed, 7 insertions(+), 8 deletions(-)
scripts/gdb/linux/proc.py +3 -0
index 6a56bba233a9..c16fab981bdd 100644
@@ -167,6 +167,9 @@ values of that process namespace"""
          if not namespace:
              raise gdb.GdbError("No namespace for current process")
 
+        gdb.write("{:^18} {:^15} {:>9} {} {} options\n".format(
+                  "mount", "super_block", "fstype", "devname", "pathname"))
+
          for vfs in lists.list_for_each_entry(namespace['list'],
                                               mount_ptr_type, "mnt_list"):
              devname = vfs['mnt_devname'].string()
@@ -190,14 +193,10 @@ values of that process namespace"""
              m_flags = int(vfs['mnt']['mnt_flags'])
              rd = "ro" if (s_flags & constants.LX_SB_RDONLY) else "rw"
 
Quoted 15 lines

scripts/gdb/linux/proc.py values of that process namespace""" · line 199

Quoted 12 lines
scripts/gdb/linux/proc.py +4 -8
-            gdb.write(
-                "{} {} {} {}{}{} 0 0\n"
-                .format(devname,
-                        pathname,
-                        fstype,
-                        rd,
-                        info_opts(FS_INFO, s_flags),
-                        info_opts(MNT_INFO, m_flags)))
+            gdb.write("{} {} {} {} {} {} {} {} 0 0\n".format(
+                      vfs.format_string(), superblock.format_string(), fstype,
+                      devname, pathname, rd, info_opts(FS_INFO, s_flags),
+                      info_opts(MNT_INFO, m_flags)))

The last three format elements should not be space-separated. The effect can even be seen in your example above.

yes, agreed. Will fix it in next version.

-ritesh

#4 lore raw

PATCH 2/2 tasks: Add task_struct addr for lx-ps cmd

In reply to Ritesh Harjani

task_struct addr in lx-ps cmd seems helpful

<e.g. o/p>
TASK PID COMM

0xffffffff82c2b8c0   0   swapper/0
0xffff888a0ba20040   1   systemd
0xffff888a0ba24040   2   kthreadd
0xffff888a0ba28040   3   rcu_gp
---
 scripts/gdb/linux/tasks.py | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
scripts/gdb/linux/tasks.py +5 -4
index 0301dc1e0138..17ec19e9b5bf 100644
@@ -73,11 +73,12 @@ class LxPs(gdb.Command):
         super(LxPs, self).__init__("lx-ps", gdb.COMMAND_DATA)
 
     def invoke(self, arg, from_tty):
+        gdb.write("{:>10} {:>12} {:>7}\n".format("TASK", "PID", "COMM"))
         for task in task_lists():
-            gdb.write("{address} {pid} {comm}\n".format(
-                address=task,
-                pid=task["pid"],
-                comm=task["comm"].string()))
+            gdb.write("{} {:^5} {}\n".format(
+                task.format_string().split()[0],
+                task["pid"].format_string(),
+                task["comm"].string()))
 
 
 LxPs()
Signature · 1 line
2.25.4
maintainer
#5 lore raw

Re: [PATCH 2/2] tasks: Add task_struct addr for lx-ps cmd

Quoted 26 lines · Ritesh Harjani

task_struct addr in lx-ps cmd seems helpful

<e.g. o/p>
TASK PID COMM

0xffffffff82c2b8c0   0   swapper/0
0xffff888a0ba20040   1   systemd
0xffff888a0ba24040   2   kthreadd
0xffff888a0ba28040   3   rcu_gp
---
 scripts/gdb/linux/tasks.py | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
scripts/gdb/linux/tasks.py +1 -1
index 0301dc1e0138..17ec19e9b5bf 100644
@@ -73,11 +73,12 @@ class LxPs(gdb.Command):
         super(LxPs, self).__init__("lx-ps", gdb.COMMAND_DATA)
 
     def invoke(self, arg, from_tty):
+        gdb.write("{:>10} {:>12} {:>7}\n".format("TASK", "PID", "COMM"))
         for task in task_lists():
-            gdb.write("{address} {pid} {comm}\n".format(

scripts/gdb/linux/tasks.py class LxPs(gdb.Command): · line 84

Quoted 10 lines
scripts/gdb/linux/tasks.py +4 -3
-                address=task,
-                pid=task["pid"],
-                comm=task["comm"].string()))
+            gdb.write("{} {:^5} {}\n".format(
+                task.format_string().split()[0],
+                task["pid"].format_string(),
+                task["comm"].string()))
 
 
 LxPs()

This patch is confusing me. We already dump the task address. What the patch changes is adding a header and some conversions of the values. Can you elaborate?

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT RDA IOT SES-DE
Corporate Competence Center Embedded Linux
#6 lore raw

Re: [PATCH 2/2] tasks: Add task_struct addr for lx-ps cmd

Quoted 35 lines · Jan Kiszka
Quoted 34 lines · Ritesh Harjani

task_struct addr in lx-ps cmd seems helpful

<e.g. o/p>

       TASK          PID    COMM
0xffffffff82c2b8c0   0   swapper/0
0xffff888a0ba20040   1   systemd
0xffff888a0ba24040   2   kthreadd
0xffff888a0ba28040   3   rcu_gp
---
  scripts/gdb/linux/tasks.py | 9 +++++----
  1 file changed, 5 insertions(+), 4 deletions(-)
scripts/gdb/linux/tasks.py +5 -4
index 0301dc1e0138..17ec19e9b5bf 100644
@@ -73,11 +73,12 @@ class LxPs(gdb.Command):
          super(LxPs, self).__init__("lx-ps", gdb.COMMAND_DATA)
 
      def invoke(self, arg, from_tty):
+        gdb.write("{:>10} {:>12} {:>7}\n".format("TASK", "PID", "COMM"))
          for task in task_lists():
-            gdb.write("{address} {pid} {comm}\n".format(
-                address=task,
-                pid=task["pid"],
-                comm=task["comm"].string()))
+            gdb.write("{} {:^5} {}\n".format(
+                task.format_string().split()[0],
+                task["pid"].format_string(),
+                task["comm"].string()))
 
 
Quoted 6 lines

scripts/gdb/linux/tasks.py class LxPs(gdb.Command): · line 84

Quoted 2 lines
scripts/gdb/linux/tasks.py +0 -0
  LxPs()

This patch is confusing me. We already dump the task address. What the patch changes is adding a header and some conversions of the values. Can you elaborate?

You are right. Sorry for the confusion. I will update the commit msg (in v2) to reflect that this patch adds the header and formats the spacing. Without the patch we get it like this:-

0xffffffff82c2b8c0 <init_task> 0 swapper/0
0xffff888a0ba20040 1 systemd
0xffff888a0ba24040 2 kthreadd
0xffff888a0ba28040 3 rcu_gp

-ritesh