24 Jan, 2018

1 commit

  • commit 883d50f56d263f70fd73c0d96b09eb36c34e9305 upstream.

    Since kernel 4.9, the thread_info has been moved into task_struct, no
    longer locates at the bottom of kernel stack.

    See commits c65eacbe290b ("sched/core: Allow putting thread_info into
    task_struct") and 15f4eae70d36 ("x86: Move thread_info into
    task_struct").

    Before fix:
    (gdb) set $current = $lx_current()
    (gdb) p $lx_thread_info($current)
    $1 = {flags = 1470918301}
    (gdb) p $current.thread_info
    $2 = {flags = 2147483648}

    After fix:
    (gdb) p $lx_thread_info($current)
    $1 = {flags = 2147483648}
    (gdb) p $current.thread_info
    $2 = {flags = 2147483648}

    Link: http://lkml.kernel.org/r/20180118210159.17223-1-imxikangjie@gmail.com
    Fixes: 15f4eae70d36 ("x86: Move thread_info into task_struct")
    Signed-off-by: Xi Kangjie
    Acked-by: Jan Kiszka
    Acked-by: Kieran Bingham
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds
    Signed-off-by: Greg Kroah-Hartman

    Xi Kangjie
     

15 Jul, 2016

5 commits

  • This reverts commit e127a73d41ac ("scripts/gdb: add a Radix Tree
    Parser")

    The python implementation of radix-tree was merged at the same time as
    the radix-tree system was heavily reworked from commit e9256efcc8e3
    ("radix-tree: introduce radix_tree_empty") to 3bcadd6fa6c4 ("radix-tree:
    free up the bottom bit of exceptional entries for reuse") and no longer
    functions, but also prevents other gdb scripts from loading.

    This functionality has not yet hit a release, so simply remove it for
    now

    Link: http://lkml.kernel.org/r/1467127337-11135-6-git-send-email-kieran@bingham.xyz
    Signed-off-by: Kieran Bingham
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Kieran Bingham
     
  • Python doesn't do automatic expansion of paths. In case one passes path
    of the from ~/foo/bar the gdb scripts won't automatically expand that
    and as a result the symbols files won't be loaded.

    Fix this by explicitly expanding all paths which begin with "~"

    Link: http://lkml.kernel.org/r/1467127337-11135-5-git-send-email-kieran@bingham.xyz
    Signed-off-by: Nikolay Borisov
    Signed-off-by: Kieran Bingham
    Reviewed-by: Jan Kiszka
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Nikolay Borisov
     
  • Since scripts/gdb/linux/constants.py is autogenerated, this should have
    been added to .gitignore when it was introduced.

    Fixes: f197d75fcad1 ("scripts/gdb: provide linux constants")
    Link: http://lkml.kernel.org/r/1467127337-11135-4-git-send-email-kieran@bingham.xyz
    Signed-off-by: Omar Sandoval
    Signed-off-by: Kieran Bingham
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Omar Sandoval
     
  • The autogenerated constants.py file was only being built on the initial
    call, and if the constants.py.in file changed. As we are utilising the
    CPP hooks, we can successfully use the call if_changed_dep rules to
    determine when to rebuild the file based on it's inclusions.

    Link: http://lkml.kernel.org/r/1467127337-11135-3-git-send-email-kieran@bingham.xyz
    Signed-off-by: Kieran Bingham
    Reported-by: Jan Kiszka
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Kieran Bingham
     
  • The constants.py generation, involves a rule to link into the main
    makefile. This rule has no command and generates a spurious warning
    message in the build logs when CONFIG_SCRIPTS_GDB is enabled.

    Fix simply by giving a no-op action

    Link: http://lkml.kernel.org/r/1467127337-11135-2-git-send-email-kieran@bingham.xyz
    Signed-off-by: Kieran Bingham
    Reported-by: Jan Kiszka
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Kieran Bingham
     

24 May, 2016

16 commits

  • 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'' marker.

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

    Link: http://lkml.kernel.org/r/d67ccf93f2479c94cb3399262b9b796e0dbefcf2.1462865983.git.jan.kiszka@siemens.com
    Signed-off-by: Kieran Bingham
    Acked-by: Dom Cote
    Tested-by: Dom Cote
    Signed-off-by: Jan Kiszka
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Kieran Bingham
     
  • When built against Python 3, GDB differs in the return type for its
    read_memory function, causing the lx-dmesg command to fail.

    Now that we have an improved read_16() we can use the new
    read_memoryview() abstraction to make lx-dmesg return valid data on both
    current Python APIs

    Tested with python 3.4 and 2.7
    Tested with gdb 7.7

    Link: http://lkml.kernel.org/r/28477b727ff7fe3101fd4e426060e8a68317a639.1462865983.git.jan.kiszka@siemens.com
    Signed-off-by: Dom Cote
    [kieran@bingham.xyz: Adjusted commit log to better reflect code changes]
    Tested-by: Kieran Bingham (Py2.7,Py3.4,GDB10)
    Signed-off-by: Kieran Bingham
    Signed-off-by: Jan Kiszka
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Dom Cote
     
  • 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

    Link: http://lkml.kernel.org/r/73621f564503137a002a639d174e4fb35f73f462.1462865983.git.jan.kiszka@siemens.com
    Signed-off-by: Dom Cote
    Tested-by: Kieran Bingham (Py2.7,Py3.4,GDB10)
    Signed-off-by: Kieran Bingham
    Signed-off-by: Jan Kiszka
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Dom Cote
     
  • The tasks module already provides helpers to find the task struct by
    pid, and the thread_info by task struct; however this is cumbersome to
    utilise on the gdb commandline.

    Wrap these two functionalities together in an extra single helper to
    allow exploring the thread info, from a PID value

    Link: http://lkml.kernel.org/r/dadc5667f053ec811eb3e3033d99d937fedbc93b.1462865983.git.jan.kiszka@siemens.com
    Signed-off-by: Kieran Bingham
    Signed-off-by: Jan Kiszka
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Kieran Bingham
     
  • 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)

    Link: http://lkml.kernel.org/r/d2028c55e50cf95a9b7f8ca0d11885174b0cc709.1462865983.git.jan.kiszka@siemens.com
    Signed-off-by: Kieran Bingham
    Signed-off-by: Jan Kiszka
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Kieran Bingham
     
  • We won't see more than 2 billion CPUs any time soon, and having cpu_list
    return long makes the output of lx-cpus a bit ugly.

    Link: http://lkml.kernel.org/r/dcb45c3b0a59e0fd321fa56ff7aa398458c689b3.1462865983.git.jan.kiszka@siemens.com
    Signed-off-by: Jan Kiszka
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Jan Kiszka
     
  • The linux kernel provides macro's for iterating against values from the
    cpu_list masks. By providing some commonly used masks, we can mirror
    the kernels helper macros with easy to use generators.

    Link: http://lkml.kernel.org/r/d045c6599771ada1999d49612ee30fd2f9acf17f.1462865983.git.jan.kiszka@siemens.com
    Signed-off-by: Kieran Bingham
    Signed-off-by: Jan Kiszka
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Kieran Bingham
     
  • 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

    Link: http://lkml.kernel.org/r/e614c7bc32d2350b4ff1627ec761a7148e65bfe6.1462865983.git.jan.kiszka@siemens.com
    Signed-off-by: Kieran Bingham
    Signed-off-by: Jan Kiszka
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Kieran Bingham
     
  • Provide iomem_resource and ioports_resource printers and command hooks

    It can be quite interesting to halt the kernel as it's booting and check
    to see this list as it is being populated.

    It should be useful in the event that a kernel is not booting, you can
    identify what memory resources have been registered

    Link: http://lkml.kernel.org/r/f0a6b9fa9c92af4d7ed2e7343ccc84150e9c6fc5.1462865983.git.jan.kiszka@siemens.com
    Signed-off-by: Kieran Bingham
    Signed-off-by: Jan Kiszka
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

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

    Link: http://lkml.kernel.org/r/4328fdb2d15ba7f1b21ad21c2eecc38d9cfc4d13.1462865983.git.jan.kiszka@siemens.com
    Signed-off-by: Kieran Bingham
    Signed-off-by: Jan Kiszka
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Kieran Bingham
     
  • 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)

    Link: http://lkml.kernel.org/r/94d533819437408b85ae5864f939dd7ca6fbfcd6.1462865983.git.jan.kiszka@siemens.com
    Signed-off-by: Kieran Bingham
    Signed-off-by: Jan Kiszka
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Kieran Bingham
     
  • If we attempt to read a value that is not available to GDB, an exception
    is raised. Most of the time, this is a good thing; however on occasion
    we will want to be able to determine if a symbol is available.

    By catching the exception to simply return None, we can determine if we
    tried to read an invalid value, without the exception taking our
    execution context away from us

    Link: http://lkml.kernel.org/r/c72b25c06fc66e1d68371154097e2cbb112555d8.1462865983.git.jan.kiszka@siemens.com
    Signed-off-by: Kieran Bingham
    Signed-off-by: Jan Kiszka
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Kieran Bingham
     
  • Simplify the module list functions with the new list_for_each_entry
    abstractions

    Link: http://lkml.kernel.org/r/ad0101c9391088608166fcec26af179868973d86.1462865983.git.jan.kiszka@siemens.com
    Signed-off-by: Kieran Bingham
    Signed-off-by: Jan Kiszka
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

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

    Link: http://lkml.kernel.org/r/2b0998564e6e5abe53585d466f87e491331fd2a4.1462865983.git.jan.kiszka@siemens.com
    Signed-off-by: Kieran Bingham
    Signed-off-by: Jan Kiszka
    Cc: Jeff Mahoney
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Kieran Bingham
     
  • Some macro's and defines are needed when parsing memory, and without
    compiling the kernel as -g3 they are not available in the debug-symbols.

    We use the pre-processor here to extract constants to a dedicated module
    for the linux debugger extensions

    Top level Kbuild is used to call in and generate the constants file,
    while maintaining dependencies on autogenerated files in
    include/generated

    Link: http://lkml.kernel.org/r/bc3df9c25f57ea72177c066a51a446fc19e2c27f.1462865983.git.jan.kiszka@siemens.com
    Signed-off-by: Kieran Bingham
    Signed-off-by: Jan Kiszka
    Cc: Michal Marek
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Kieran Bingham
     
  • This takes the MODULE_REF_BASE into account.

    Link: http://lkml.kernel.org/r/d926d2d54caa034adb964b52215090cbdb875249.1462865983.git.jan.kiszka@siemens.com
    Signed-off-by: Jan Kiszka
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Jan Kiszka
     

23 Mar, 2016

3 commits

  • Commit 7523e4dc5057 ("module: use a structure to encapsulate layout.")
    factored out the module_layout structure. Adjust the symbol loader and
    the lsmod command to this.

    Signed-off-by: Jan Kiszka
    Reviewed-by: Kieran Bingham
    Tested-by: Kieran Bingham (qemu-{ARM,x86})
    Cc: Rusty Russell
    Cc: Jiri Kosina
    Cc: Jason Wessel
    Cc: [4.4+]
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Jan Kiszka
     
  • lx-cmdline Report the Linux Commandline used in the current kernel

    [jan.kiszka@siemens.com: remove blank line from help output and fix pep8 warning]
    Signed-off-by: Kieran Bingham
    Signed-off-by: Jan Kiszka
    Cc: Jason Wessel
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Kieran Bingham
     
  • lx-version Report the Linux Version of the current kernel.

    Add a command to identify the version specified by the banner in the
    debugged kernel.

    This lets the user identify the kernel of the running kernel, and will
    let later scripts compare the banner of the attached kernel against the
    banner in the vmlinux symbols files to verify that the files are
    correct.

    [jan.kiszka@siemens.com: remove blank line from help output and fix pep8 warning]
    Signed-off-by: Kieran Bingham
    Signed-off-by: Jan Kiszka
    Cc: Jason Wessel
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Kieran Bingham
     

01 Jul, 2015

7 commits


29 May, 2015

1 commit

  • Commit 2f35c41f58a9 ("module: Replace module_ref with atomic_t refcnt")
    changes the way refcnt is handled but did not update the gdb script to
    use the new variable.

    Since refcnt is not per-cpu anymore, we can directly read its value.

    Signed-off-by: Adrien Schildknecht
    Reviewed-by: Jan Kiszka
    Cc: Pantelis Koukousoulas
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Adrien Schildknecht
     

01 Mar, 2015

1 commit


18 Feb, 2015

6 commits

  • While reporting the (refreshed) list of modules on automatic updates we
    may hit the page boundary of the output console and cause a stop if
    pagination is enabled. However, gdb does not accept user input while
    running over the breakpoint handler. So we get stuck, and the user is
    forced to interrupt gdb.

    Resolve this by disabling pagination during automatic symbol updates. We
    restore the user's configuration once done.

    Signed-off-by: Jan Kiszka
    Cc: Thomas Gleixner
    Cc: Jason Wessel
    Cc: Andi Kleen
    Cc: Ben Widawsky
    Cc: Borislav Petkov
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Jan Kiszka
     
  • Yet another code simplification.

    Signed-off-by: Jan Kiszka
    Cc: Thomas Gleixner
    Cc: Jason Wessel
    Cc: Andi Kleen
    Cc: Ben Widawsky
    Cc: Borislav Petkov
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Jan Kiszka
     
  • Analogously to the task list, convert the module list to a generator
    function. It noticeably simplifies the code.

    Signed-off-by: Jan Kiszka
    Cc: Thomas Gleixner
    Cc: Jason Wessel
    Cc: Andi Kleen
    Cc: Ben Widawsky
    Cc: Borislav Petkov
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Jan Kiszka
     
  • The iterator does not return any task_struct from the thread_group list
    because the first condition in the 'if not t or ...' will only be the
    first time None.

    Instead of keeping track of the state ourself in the next() function, we
    fall back using Python's generator.

    Signed-off-by: Daniel Wagner
    Signed-off-by: Jan Kiszka
    Cc: Thomas Gleixner
    Cc: Jason Wessel
    Cc: Andi Kleen
    Cc: Ben Widawsky
    Cc: Borislav Petkov
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Daniel Wagner
     
  • Using the gdb scripts leaves byte-compiled python files in the scripts/
    directory. These should be ignored by git.

    [jan.kiszka@siemens.com: drop redundant mrproper rule as suggested by Michal]
    Signed-off-by: Daniel Thompson
    Signed-off-by: Jan Kiszka
    Cc: Michal Marek
    Cc: Thomas Gleixner
    Cc: Jason Wessel
    Cc: Andi Kleen
    Cc: Ben Widawsky
    Cc: Borislav Petkov
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Daniel Thompson
     
  • I tried to use these scripts in an ubuntu 14.04 host (gdb 7.7 compiled
    against python 3.3) but there were several errors.

    I believe this patch fixes these issues so that the commands now work (I
    tested lx-symbols, lx-dmesg, lx-lsmod).

    Main issues that needed to be resolved:

    * In python 2 iterators have a "next()" method. In python 3 it is
    __next__() instead (so let's just add both).

    * In older python versions there was an implicit conversion
    in object.__format__() (used when an object is in string.format())
    where it was converting the object to str first and then
    calling str's __format__(). This has now been removed so
    we must explicitly convert to str the objects for which
    we need to keep this behavior.

    * In dmesg.py: in python 3 log_buf is now a "memoryview" object
    which needs to be converted to a string in order to use string
    methods like "splitlines()". Luckily memoryview exists in
    python 2.7.6 as well, so we can convert log_buf to memoryview
    and use the same code in both python 2 and python 3.

    This version of the patch has now been tested with gdb 7.7 and both python
    3.4 and python 2.7.6 (I think asking for at least python 2.7.6 is a
    reasonable requirement instead of complicating the code with version
    checks etc).

    Signed-off-by: Pantelis Koukousoulas
    Signed-off-by: Jan Kiszka
    Cc: Thomas Gleixner
    Cc: Jason Wessel
    Cc: Andi Kleen
    Cc: Ben Widawsky
    Cc: Borislav Petkov
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Pantelis Koukousoulas