Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1397792 > unrolled thread

[PATCH 00/18] scripts/gdb: Updates for 4.7

Started byJan Kiszka <jan.kiszka@siemens.com>
First post2016-05-10 09:50 +0200
Last post2016-05-10 09:50 +0200
Articles 9 — 1 participant

Back to article view | Back to linux.kernel


Contents

  [PATCH 00/18] scripts/gdb: Updates for 4.7 Jan Kiszka <jan.kiszka@siemens.com> - 2016-05-10 09:50 +0200
    [PATCH 13/18] scripts/gdb: Add documentation example for radix tree Jan Kiszka <jan.kiszka@siemens.com> - 2016-05-10 09:50 +0200
    [PATCH 03/18] scripts/gdb: Provide kernel list item generators Jan Kiszka <jan.kiszka@siemens.com> - 2016-05-10 09:50 +0200
    [PATCH 12/18] scripts/gdb: Add a Radix Tree Parser Jan Kiszka <jan.kiszka@siemens.com> - 2016-05-10 09:50 +0200
    [PATCH 06/18] scripts/gdb: Support !CONFIG_MODULES gracefully Jan Kiszka <jan.kiszka@siemens.com> - 2016-05-10 09:50 +0200
    [PATCH 07/18] scripts/gdb: Provide a dentry_name VFS path helper Jan Kiszka <jan.kiszka@siemens.com> - 2016-05-10 09:50 +0200
    [PATCH 17/18] scripts/gdb: decode bytestream on dmesg for Python3 Jan Kiszka <jan.kiszka@siemens.com> - 2016-05-10 09:50 +0200
    [PATCH 09/18] scripts/gdb: Add mount point list command Jan Kiszka <jan.kiszka@siemens.com> - 2016-05-10 09:50 +0200
    [PATCH 15/18] scripts/gdb: Improve types abstraction for gdb python scripts Jan Kiszka <jan.kiszka@siemens.com> - 2016-05-10 09:50 +0200

#1397792 — [PATCH 00/18] scripts/gdb: Updates for 4.7

FromJan Kiszka <jan.kiszka@siemens.com>
Date2016-05-10 09:50 +0200
Subject[PATCH 00/18] scripts/gdb: Updates for 4.7
Message-ID<rxaAx-6l0-3@gated-at.bofh.it>
Hi Andrew,

please include the following enhancements and fixed for the gdb scripts
in your queue.

This adds a number of new commands and helper functions, contributed by
Kieran, and fixes lx-dmesg for Python 3 as well as corrects the output
of lx-lsmod.

Kieran stepped up to support me significantly with the maintenance of
the script. Andrew, it may very well be that you will receive the next
merge request from him already.

Jan

CC: Dom Cote <buzdelabuz2+git@gmail.com>
CC: Jeff Mahoney <jeffm@suse.com>
Cc: Jonathan Corbet <corbet@lwn.net>
CC: Kieran Bingham <kieran.bingham@linaro.org>
CC: Kieran Bingham <kieran@bingham.xyz>
Cc: linux-doc@vger.kernel.org
CC: linux-kbuild@vger.kernel.org
CC: mmarek@suse.com

Dom Cote (2):
  scripts/gdb: Improve types abstraction for gdb python scripts
  scripts/gdb: Fix issue with dmesg.py and python 3.X

Jan Kiszka (2):
  scripts/gdb: Adjust module reference counter reported by lx-lsmod
  scripts/gdb: Cast CPU numbers to integer

Kieran Bingham (14):
  scripts/gdb: Provide linux constants
  scripts/gdb: Provide kernel list item generators
  scripts/gdb: Convert modules usage to lists functions
  scripts/gdb: Provide exception catching parser
  scripts/gdb: Support !CONFIG_MODULES gracefully
  scripts/gdb: Provide a dentry_name VFS path helper
  scripts/gdb: Add io resource readers
  scripts/gdb: Add mount point list command
  scripts/gdb: Add cpu iterators
  scripts/gdb: Add a Radix Tree Parser
  scripts/gdb: Add documentation example for radix tree
  scripts/gdb: Add lx_thread_info_by_pid helper
  scripts/gdb: decode bytestream on dmesg for Python3
  MAINTAINERS: Add co-maintainer for scripts/gdb

 Documentation/gdb-kernel-debugging.txt |  21 +++++
 Kbuild                                 |  10 +++
 MAINTAINERS                            |   1 +
 scripts/gdb/linux/Makefile             |  12 ++-
 scripts/gdb/linux/constants.py.in      |  59 +++++++++++++
 scripts/gdb/linux/cpus.py              |  38 ++++++++
 scripts/gdb/linux/dmesg.py             |  11 +--
 scripts/gdb/linux/lists.py             |  21 +++++
 scripts/gdb/linux/modules.py           |  24 +++--
 scripts/gdb/linux/proc.py              | 156 +++++++++++++++++++++++++++++++++
 scripts/gdb/linux/radixtree.py         |  97 ++++++++++++++++++++
 scripts/gdb/linux/tasks.py             |  19 ++++
 scripts/gdb/linux/utils.py             |  32 ++++++-
 scripts/gdb/vmlinux-gdb.py             |   2 +
 14 files changed, 482 insertions(+), 21 deletions(-)
 create mode 100644 scripts/gdb/linux/constants.py.in
 create mode 100644 scripts/gdb/linux/radixtree.py

-- 
2.1.4

[toc] | [next] | [standalone]


#1397794 — [PATCH 13/18] scripts/gdb: Add documentation example for radix tree

FromJan Kiszka <jan.kiszka@siemens.com>
Date2016-05-10 09:50 +0200
Subject[PATCH 13/18] scripts/gdb: Add documentation example for radix tree
Message-ID<rxaAz-6l0-41@gated-at.bofh.it>
In reply to#1397792
From: Kieran Bingham <kieran.bingham@linaro.org>

Provide a worked example for utilising the lx_radix_tree_lookup function

Cc: Jonathan Corbet <corbet@lwn.net>
Cc: linux-doc@vger.kernel.org

Signed-off-by: Kieran Bingham <kieran.bingham@linaro.org>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 Documentation/gdb-kernel-debugging.txt | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/Documentation/gdb-kernel-debugging.txt b/Documentation/gdb-kernel-debugging.txt
index 7050ce8..4ab7d43 100644
--- a/Documentation/gdb-kernel-debugging.txt
+++ b/Documentation/gdb-kernel-debugging.txt
@@ -139,6 +139,27 @@ Examples of using the Linux-provided gdb helpers
       start_comm = "swapper/2\000\000\000\000\000\000"
     }
 
+ o Dig into a radix tree data structure, such as the IRQ descriptors:
+    (gdb) print (struct irq_desc)$lx_radix_tree_lookup(irq_desc_tree, 18)
+    $6 = {
+      irq_common_data = {
+        state_use_accessors = 67584,
+        handler_data = 0x0 <__vectors_start>,
+        msi_desc = 0x0 <__vectors_start>,
+        affinity = {{
+            bits = {65535}
+          }}
+      },
+      irq_data = {
+        mask = 0,
+        irq = 18,
+        hwirq = 27,
+        common = 0xee803d80,
+        chip = 0xc0eb0854 <gic_data>,
+        domain = 0xee808000,
+        parent_data = 0x0 <__vectors_start>,
+        chip_data = 0xc0eb0854 <gic_data>
+      } <... trimmed ...>
 
 List of commands and functions
 ------------------------------
-- 
2.1.4

[toc] | [prev] | [next] | [standalone]


#1397797 — [PATCH 03/18] scripts/gdb: Provide kernel list item generators

FromJan Kiszka <jan.kiszka@siemens.com>
Date2016-05-10 09:50 +0200
Subject[PATCH 03/18] scripts/gdb: Provide kernel list item generators
Message-ID<rxaAz-6l0-57@gated-at.bofh.it>
In reply to#1397792
From: Kieran Bingham <kieran.bingham@linaro.org>

Facilitate linked-list items by providing a generator to return
the dereferenced, and type-cast objects from a kernel linked list

CC: Jeff Mahoney <jeffm@suse.com>

Signed-off-by: Kieran Bingham <kieran.bingham@linaro.org>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 scripts/gdb/linux/lists.py | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/scripts/gdb/linux/lists.py b/scripts/gdb/linux/lists.py
index 3a3775b..2f335fb 100644
--- a/scripts/gdb/linux/lists.py
+++ b/scripts/gdb/linux/lists.py
@@ -18,6 +18,27 @@ from linux import utils
 list_head = utils.CachedType("struct list_head")
 
 
+def list_for_each(head):
+    if head.type == list_head.get_type().pointer():
+        head = head.dereference()
+    elif head.type != list_head.get_type():
+        raise gdb.GdbError("Must be struct list_head not {}"
+                           .format(head.type))
+
+    node = head['next'].dereference()
+    while node.address != head.address:
+        yield node.address
+        node = node['next'].dereference()
+
+
+def list_for_each_entry(head, gdbtype, member):
+    for node in list_for_each(head):
+        if node.type != list_head.get_type().pointer():
+            raise TypeError("Type {} found. Expected struct list_head *."
+                            .format(node.type))
+        yield utils.container_of(node, gdbtype, member)
+
+
 def list_check(head):
     nb = 0
     if (head.type == list_head.get_type().pointer()):
-- 
2.1.4

[toc] | [prev] | [next] | [standalone]


#1397803 — [PATCH 12/18] scripts/gdb: Add a Radix Tree Parser

FromJan Kiszka <jan.kiszka@siemens.com>
Date2016-05-10 09:50 +0200
Subject[PATCH 12/18] scripts/gdb: Add a Radix Tree Parser
Message-ID<rxaAA-6l0-59@gated-at.bofh.it>
In reply to#1397792
From: Kieran Bingham <kieran.bingham@linaro.org>

Linux makes use of the Radix Tree data structure to store pointers indexed
by integer values. This structure is utilised across many structures in
the kernel including the IRQ descriptor tables, and several filesystems.

This module provides a method to lookup values from a structure given
its head node.

Usage:

The function lx_radix_tree_lookup, must be given a symbol of type
struct radix_tree_root, and an index into that tree.

The object returned is a generic integer value, and must be cast
correctly to the type based on the storage in the data structure.

For example, to print the irq descriptor in the sparse irq_desc_tree at
index 18, try the following:

 (gdb) print (struct irq_desc)$lx_radix_tree_lookup(irq_desc_tree, 18)

Signed-off-by: Kieran Bingham <kieran.bingham@linaro.org>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 scripts/gdb/linux/constants.py.in |  7 +++
 scripts/gdb/linux/radixtree.py    | 97 +++++++++++++++++++++++++++++++++++++++
 scripts/gdb/vmlinux-gdb.py        |  1 +
 3 files changed, 105 insertions(+)
 create mode 100644 scripts/gdb/linux/radixtree.py

diff --git a/scripts/gdb/linux/constants.py.in b/scripts/gdb/linux/constants.py.in
index 7986f4e..07e6c2b 100644
--- a/scripts/gdb/linux/constants.py.in
+++ b/scripts/gdb/linux/constants.py.in
@@ -14,6 +14,7 @@
 
 #include <linux/fs.h>
 #include <linux/mount.h>
+#include <linux/radix-tree.h>
 
 /* We need to stringify expanded macros so that they can be parsed */
 
@@ -50,3 +51,9 @@ LX_VALUE(MNT_NOEXEC)
 LX_VALUE(MNT_NOATIME)
 LX_VALUE(MNT_NODIRATIME)
 LX_VALUE(MNT_RELATIME)
+
+/* linux/radix-tree.h */
+LX_VALUE(RADIX_TREE_INDIRECT_PTR)
+LX_GDBPARSED(RADIX_TREE_HEIGHT_MASK)
+LX_GDBPARSED(RADIX_TREE_MAP_SHIFT)
+LX_GDBPARSED(RADIX_TREE_MAP_MASK)
diff --git a/scripts/gdb/linux/radixtree.py b/scripts/gdb/linux/radixtree.py
new file mode 100644
index 0000000..0fdef4e
--- /dev/null
+++ b/scripts/gdb/linux/radixtree.py
@@ -0,0 +1,97 @@
+#
+# gdb helper commands and functions for Linux kernel debugging
+#
+#  Radix Tree Parser
+#
+# Copyright (c) 2016 Linaro Ltd
+#
+# Authors:
+#  Kieran Bingham <kieran.bingham@linaro.org>
+#
+# This work is licensed under the terms of the GNU GPL version 2.
+#
+
+import gdb
+
+from linux import utils
+from linux import constants
+
+radix_tree_root_type = utils.CachedType("struct radix_tree_root")
+radix_tree_node_type = utils.CachedType("struct radix_tree_node")
+
+
+def is_indirect_ptr(node):
+    long_type = utils.get_long_type()
+    return (node.cast(long_type) & constants.LX_RADIX_TREE_INDIRECT_PTR)
+
+
+def indirect_to_ptr(node):
+    long_type = utils.get_long_type()
+    node_type = node.type
+    indirect_ptr = node.cast(long_type) & ~constants.LX_RADIX_TREE_INDIRECT_PTR
+    return indirect_ptr.cast(node_type)
+
+
+def maxindex(height):
+    height = height & constants.LX_RADIX_TREE_HEIGHT_MASK
+    return gdb.parse_and_eval("height_to_maxindex["+str(height)+"]")
+
+
+def lookup(root, index):
+    if root.type == radix_tree_root_type.get_type().pointer():
+        root = root.dereference()
+    elif root.type != radix_tree_root_type.get_type():
+        raise gdb.GdbError("Must be struct radix_tree_root not {}"
+                           .format(root.type))
+
+    node = root['rnode']
+    if node is 0:
+        return None
+
+    if not (is_indirect_ptr(node)):
+        if (index > 0):
+            return None
+        return node
+
+    node = indirect_to_ptr(node)
+
+    height = node['path'] & constants.LX_RADIX_TREE_HEIGHT_MASK
+    if (index > maxindex(height)):
+        return None
+
+    shift = (height-1) * constants.LX_RADIX_TREE_MAP_SHIFT
+
+    while True:
+        new_index = (index >> shift) & constants.LX_RADIX_TREE_MAP_MASK
+        slot = node['slots'][new_index]
+
+        node = slot.cast(node.type.pointer()).dereference()
+        if node is 0:
+            return None
+
+        shift -= constants.LX_RADIX_TREE_MAP_SHIFT
+        height -= 1
+
+        if (height <= 0):
+            break
+
+    return node
+
+
+class LxRadixTree(gdb.Function):
+    """ Lookup and return a node from a RadixTree.
+
+$lx_radix_tree_lookup(root_node [, index]): Return the node at the given index.
+If index is omitted, the root node is dereferenced and returned."""
+
+    def __init__(self):
+        super(LxRadixTree, self).__init__("lx_radix_tree_lookup")
+
+    def invoke(self, root, index=0):
+        result = lookup(root, index)
+        if result is None:
+            raise gdb.GdbError("No entry in tree at index {}".format(index))
+
+        return result
+
+LxRadixTree()
diff --git a/scripts/gdb/vmlinux-gdb.py b/scripts/gdb/vmlinux-gdb.py
index 6e0b0af..3a80ad6 100644
--- a/scripts/gdb/vmlinux-gdb.py
+++ b/scripts/gdb/vmlinux-gdb.py
@@ -31,3 +31,4 @@ else:
     import linux.lists
     import linux.proc
     import linux.constants
+    import linux.radixtree
-- 
2.1.4

[toc] | [prev] | [next] | [standalone]


#1397805 — [PATCH 06/18] scripts/gdb: Support !CONFIG_MODULES gracefully

FromJan Kiszka <jan.kiszka@siemens.com>
Date2016-05-10 09:50 +0200
Subject[PATCH 06/18] scripts/gdb: Support !CONFIG_MODULES gracefully
Message-ID<rxaAA-6l0-65@gated-at.bofh.it>
In reply to#1397792
From: Kieran Bingham <kieran.bingham@linaro.org>

If CONFIG_MODULES is not enabled, lx-lsmod tries to find
a non-existent symbol and generates an unfriendly traceback:

(gdb) lx-lsmod
Address    Module                  Size  Used by
Traceback (most recent call last):
  File "scripts/gdb/linux/modules.py", line 75, in invoke
    for module in module_list():
  File "scripts/gdb/linux/modules.py", line 24, in module_list
    module_ptr_type = module_type.get_type().pointer()
  File "scripts/gdb/linux/utils.py", line 28, in get_type
    self._type = gdb.lookup_type(self._name)
gdb.error: No struct type named module.
Error occurred in Python command: No struct type named module.

Catch the error and return an empty module_list() for a clean command
output as follows:

(gdb) lx-lsmod
Address    Module                  Size  Used by
(gdb)

Signed-off-by: Kieran Bingham <kieran.bingham@linaro.org>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 scripts/gdb/linux/modules.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/scripts/gdb/linux/modules.py b/scripts/gdb/linux/modules.py
index 62557dd..441b2323 100644
--- a/scripts/gdb/linux/modules.py
+++ b/scripts/gdb/linux/modules.py
@@ -21,8 +21,11 @@ module_type = utils.CachedType("struct module")
 
 def module_list():
     global module_type
+    modules = utils.gdb_eval_or_none("modules")
+    if modules is None:
+        return
+
     module_ptr_type = module_type.get_type().pointer()
-    modules = gdb.parse_and_eval("modules")
 
     for module in lists.list_for_each_entry(modules, module_ptr_type, "list"):
         yield module
-- 
2.1.4

[toc] | [prev] | [next] | [standalone]


#1397809 — [PATCH 07/18] scripts/gdb: Provide a dentry_name VFS path helper

FromJan Kiszka <jan.kiszka@siemens.com>
Date2016-05-10 09:50 +0200
Subject[PATCH 07/18] scripts/gdb: Provide a dentry_name VFS path helper
Message-ID<rxaAB-6l0-75@gated-at.bofh.it>
In reply to#1397792
From: Kieran Bingham <kieran.bingham@linaro.org>

Walk the VFS entries, pre-pending the iname strings to generate a full
VFS path name from a dentry.

Signed-off-by: Kieran Bingham <kieran.bingham@linaro.org>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 scripts/gdb/linux/utils.py | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/scripts/gdb/linux/utils.py b/scripts/gdb/linux/utils.py
index dbe2ad7..de03a6b 100644
--- a/scripts/gdb/linux/utils.py
+++ b/scripts/gdb/linux/utils.py
@@ -161,3 +161,11 @@ def gdb_eval_or_none(expresssion):
         return gdb.parse_and_eval(expresssion)
     except:
         return None
+
+
+def dentry_name(d):
+    parent = d['d_parent']
+    if parent == d or parent == 0:
+        return ""
+    p = dentry_name(d['d_parent']) + "/"
+    return p + d['d_iname'].string()
-- 
2.1.4

[toc] | [prev] | [next] | [standalone]


#1397810 — [PATCH 17/18] scripts/gdb: decode bytestream on dmesg for Python3

FromJan Kiszka <jan.kiszka@siemens.com>
Date2016-05-10 09:50 +0200
Subject[PATCH 17/18] scripts/gdb: decode bytestream on dmesg for Python3
Message-ID<rxaAB-6l0-73@gated-at.bofh.it>
In reply to#1397792
From: Kieran Bingham <kieran@bingham.xyz>

The recent fixes to lx-dmesg, now allow the command to print
successfully on Python3, however the python interpreter wraps the bytes
for each line with a b'<text>' marker.

To remove this, we need to decode the line, where .decode() will default
to 'UTF-8'

Signed-off-by: Kieran Bingham <kieran@bingham.xyz>
Acked-by: Dom Cote <buzdelabuz2@gmail.com>
Tested-by: Dom Cote <buzdelabuz2@gmail.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 scripts/gdb/linux/dmesg.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/scripts/gdb/linux/dmesg.py b/scripts/gdb/linux/dmesg.py
index 04d6719..f9b92ec 100644
--- a/scripts/gdb/linux/dmesg.py
+++ b/scripts/gdb/linux/dmesg.py
@@ -51,10 +51,10 @@ class LxDmesg(gdb.Command):
                 continue
 
             text_len = utils.read_u16(log_buf[pos + 10:pos + 12])
-            text = log_buf[pos + 16:pos + 16 + text_len]
+            text = log_buf[pos + 16:pos + 16 + text_len].decode()
             time_stamp = utils.read_u64(log_buf[pos:pos + 8])
 
-            for line in memoryview(text).tobytes().splitlines():
+            for line in text.splitlines():
                 gdb.write("[{time:12.6f}] {line}\n".format(
                     time=time_stamp / 1000000000.0,
                     line=line))
-- 
2.1.4

[toc] | [prev] | [next] | [standalone]


#1397811 — [PATCH 09/18] scripts/gdb: Add mount point list command

FromJan Kiszka <jan.kiszka@siemens.com>
Date2016-05-10 09:50 +0200
Subject[PATCH 09/18] scripts/gdb: Add mount point list command
Message-ID<rxaAB-6l0-71@gated-at.bofh.it>
In reply to#1397792
From: Kieran Bingham <kieran.bingham@linaro.org>

lx-mounts will identify current mount points based on the 'init_task'
namespace by default, as we do not yet have a kernel thread list
implementation to select the current running thread.

Optionally, a user can specify a PID to list from that process'
namespace

Signed-off-by: Kieran Bingham <kieran.bingham@linaro.org>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 scripts/gdb/linux/constants.py.in | 20 ++++++++
 scripts/gdb/linux/proc.py         | 99 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 119 insertions(+)

diff --git a/scripts/gdb/linux/constants.py.in b/scripts/gdb/linux/constants.py.in
index 79d9d00..7986f4e 100644
--- a/scripts/gdb/linux/constants.py.in
+++ b/scripts/gdb/linux/constants.py.in
@@ -12,7 +12,11 @@
  *
  */
 
+#include <linux/fs.h>
+#include <linux/mount.h>
+
 /* We need to stringify expanded macros so that they can be parsed */
+
 #define STRING(x) #x
 #define XSTRING(x) STRING(x)
 
@@ -30,3 +34,19 @@
 <!-- end-c-headers -->
 
 import gdb
+
+/* linux/fs.h */
+LX_VALUE(MS_RDONLY)
+LX_VALUE(MS_SYNCHRONOUS)
+LX_VALUE(MS_MANDLOCK)
+LX_VALUE(MS_DIRSYNC)
+LX_VALUE(MS_NOATIME)
+LX_VALUE(MS_NODIRATIME)
+
+/* linux/mount.h */
+LX_VALUE(MNT_NOSUID)
+LX_VALUE(MNT_NODEV)
+LX_VALUE(MNT_NOEXEC)
+LX_VALUE(MNT_NOATIME)
+LX_VALUE(MNT_NODIRATIME)
+LX_VALUE(MNT_RELATIME)
diff --git a/scripts/gdb/linux/proc.py b/scripts/gdb/linux/proc.py
index d855b2f..38b1f09 100644
--- a/scripts/gdb/linux/proc.py
+++ b/scripts/gdb/linux/proc.py
@@ -12,6 +12,10 @@
 #
 
 import gdb
+from linux import constants
+from linux import utils
+from linux import tasks
+from linux import lists
 
 
 class LxCmdLine(gdb.Command):
@@ -96,3 +100,98 @@ Equivalent to cat /proc/ioports on a running target"""
         return show_lx_resources("ioport_resource")
 
 LxIOPorts()
+
+
+# Mount namespace viewer
+#  /proc/mounts
+
+def info_opts(lst, opt):
+    opts = ""
+    for key, string in lst.items():
+        if opt & key:
+            opts += string
+    return opts
+
+
+FS_INFO = {constants.LX_MS_SYNCHRONOUS: ",sync",
+           constants.LX_MS_MANDLOCK: ",mand",
+           constants.LX_MS_DIRSYNC: ",dirsync",
+           constants.LX_MS_NOATIME: ",noatime",
+           constants.LX_MS_NODIRATIME: ",nodiratime"}
+
+MNT_INFO = {constants.LX_MNT_NOSUID: ",nosuid",
+            constants.LX_MNT_NODEV: ",nodev",
+            constants.LX_MNT_NOEXEC: ",noexec",
+            constants.LX_MNT_NOATIME: ",noatime",
+            constants.LX_MNT_NODIRATIME: ",nodiratime",
+            constants.LX_MNT_RELATIME: ",relatime"}
+
+mount_type = utils.CachedType("struct mount")
+mount_ptr_type = mount_type.get_type().pointer()
+
+
+class LxMounts(gdb.Command):
+    """Report the VFS mounts of the current process namespace.
+
+Equivalent to cat /proc/mounts on a running target
+An integer value can be supplied to display the mount
+values of that process namespace"""
+
+    def __init__(self):
+        super(LxMounts, self).__init__("lx-mounts", gdb.COMMAND_DATA)
+
+    # Equivalent to proc_namespace.c:show_vfsmnt
+    # However, that has the ability to call into s_op functions
+    # whereas we cannot and must make do with the information we can obtain.
+    def invoke(self, arg, from_tty):
+        argv = gdb.string_to_argv(arg)
+        if len(argv) >= 1:
+            try:
+                pid = int(argv[0])
+            except:
+                raise gdb.GdbError("Provide a PID as integer value")
+        else:
+            pid = 1
+
+        task = tasks.get_task_by_pid(pid)
+        if not task:
+            raise gdb.GdbError("Couldn't find a process with PID {}"
+                               .format(pid))
+
+        namespace = task['nsproxy']['mnt_ns']
+        if not namespace:
+            raise gdb.GdbError("No namespace for current process")
+
+        for vfs in lists.list_for_each_entry(namespace['list'],
+                                             mount_ptr_type, "mnt_list"):
+            devname = vfs['mnt_devname'].string()
+            devname = devname if devname else "none"
+
+            pathname = ""
+            parent = vfs
+            while True:
+                mntpoint = parent['mnt_mountpoint']
+                pathname = utils.dentry_name(mntpoint) + pathname
+                if (parent == parent['mnt_parent']):
+                    break
+                parent = parent['mnt_parent']
+
+            if (pathname == ""):
+                pathname = "/"
+
+            superblock = vfs['mnt']['mnt_sb']
+            fstype = superblock['s_type']['name'].string()
+            s_flags = int(superblock['s_flags'])
+            m_flags = int(vfs['mnt']['mnt_flags'])
+            rd = "ro" if (s_flags & constants.LX_MS_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)))
+
+LxMounts()
-- 
2.1.4

[toc] | [prev] | [next] | [standalone]


#1397813 — [PATCH 15/18] scripts/gdb: Improve types abstraction for gdb python scripts

FromJan Kiszka <jan.kiszka@siemens.com>
Date2016-05-10 09:50 +0200
Subject[PATCH 15/18] scripts/gdb: Improve types abstraction for gdb python scripts
Message-ID<rxaAB-6l0-79@gated-at.bofh.it>
In reply to#1397792
From: Dom Cote <buzdelabuz2+git@gmail.com>

Change the read_u16 function so it accepts both 'str' and 'byte'
as type for the arguments.

When calling read_memory() from gdb API, depending on if
it was built with 2.7 or 3.X, the format used to return the
data will differ ( 'str' for 2.7, and 'byte' for 3.X ).

Add a function read_memoryview() to be able to get a
'memoryview' object back from read_memory() both with
python 2.7 and 3.X .

Tested with python 3.4 and 2.7
Tested with gdb 7.7

Signed-off-by: Dom Cote <buzdelabuz2+git@gmail.com>
Tested-by: Kieran Bingham <kieran@bingham.xyz> (Py2.7,Py3.4,GDB10)
Signed-off-by: Kieran Bingham <kieran@bingham.xyz>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 scripts/gdb/linux/utils.py | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/scripts/gdb/linux/utils.py b/scripts/gdb/linux/utils.py
index de03a6b..5080587 100644
--- a/scripts/gdb/linux/utils.py
+++ b/scripts/gdb/linux/utils.py
@@ -87,11 +87,24 @@ def get_target_endianness():
     return target_endianness
 
 
+def read_memoryview(inf, start, length):
+    return memoryview(inf.read_memory(start, length))
+
+
 def read_u16(buffer):
+    value = [0, 0]
+
+    if type(buffer[0]) is str:
+        value[0] = ord(buffer[0])
+        value[1] = ord(buffer[1])
+    else:
+        value[0] = buffer[0]
+        value[1] = buffer[1]
+
     if get_target_endianness() == LITTLE_ENDIAN:
-        return ord(buffer[0]) + (ord(buffer[1]) << 8)
+        return value[0] + (value[1] << 8)
     else:
-        return ord(buffer[1]) + (ord(buffer[0]) << 8)
+        return value[1] + (value[0] << 8)
 
 
 def read_u32(buffer):
-- 
2.1.4

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web