Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
f29e1de
crash.types.task: improve task flag handling
jeffmahoney Apr 29, 2019
86422cb
crash.commands.ps: add support for TASK_IDLE
jeffmahoney Apr 29, 2019
68f6630
crash.commands.help: sort commands in help output
jeffmahoney Sep 19, 2018
4fb4c3a
crash.util: add struct_has_member
jeffmahoney Apr 29, 2019
7fe8aa7
crash.types.task: handle anonymous sub-structure in mm_struct
jeffmahoney Apr 29, 2019
b8de0ab
crash.util: add uuid decoding
jeffmahoney May 1, 2019
e75bc23
crash.util: add decode_flags helper
jeffmahoney Apr 26, 2019
81cb971
crash.types.{,k}list: use the type from the symbol when available
jeffmahoney Sep 19, 2018
736fdf7
crash.types.list: add list_empty
jeffmahoney Apr 26, 2019
df92870
crash.types.list: fix cycle tests
jeffmahoney Apr 22, 2019
87aec81
tests: clear file during test teardown
jeffmahoney Apr 22, 2019
ff7ef81
crash.kernel: convert setup to use DelayedSymvals
jeffmahoney Apr 22, 2019
a132e76
crash.arch: add baseline ppc64 support
jeffmahoney Apr 22, 2019
bbe3d6f
crash.types.bitmap: add find first/last/next helpers
jeffmahoney Apr 22, 2019
527e044
crash: use new gdb.Target to create standalone target
jeffmahoney Apr 22, 2019
afdd5b2
crash.types.module: create module for modules
jeffmahoney May 7, 2019
96be843
kdump.target: don't specify offset for .data..percpu
jeffmahoney May 1, 2019
fa71477
crash.types.percpu: handle missing pcpu_nr_slots
jeffmahoney May 6, 2019
c6ec4bc
crash.types.percpu: get_percpu_var, raise exception with passed val
jeffmahoney May 1, 2019
7502b34
crash.types.cpu: fix online cpu mask and add possible cpu mask
jeffmahoney May 7, 2019
36a58b8
crash.types.percpu: better percpu handling
jeffmahoney Apr 22, 2019
118bbfe
crash.types.percpu: separate the all-cpus and single-cpu cases
jeffmahoney May 21, 2019
7b38ed4
crash.types.percpu: add percpu_counter_sum
jeffmahoney Apr 30, 2019
a515eef
crash: auto-select crashing task and print backtrace on startup
jeffmahoney Apr 22, 2019
f6feb54
crash.sh: use $TMPDIR for gdbinit in --gdb mode
jeffmahoney May 1, 2019
fe1c40e
crash.kernel: use new KernelError exception to report errors during s…
jeffmahoney May 1, 2019
18707a4
crash.kernel: add debug option to load_modules
jeffmahoney May 1, 2019
823e505
crash.kernel: use objfile.has_symbols() to detect debuginfo
jeffmahoney May 1, 2019
58b7c35
crash.util: promote to be its own sub-package
jeffmahoney May 3, 2019
4175429
crash: add static percpu regions for modules
jeffmahoney May 1, 2019
40352e2
crash.kernel: handle failure to add module symbols
jeffmahoney May 1, 2019
9a86bc6
crash.kernel: improve and document debuginfo and module loading
jeffmahoney May 1, 2019
95b3d0d
crash.kernel: check module version on load
jeffmahoney Apr 26, 2019
917c3a9
crash.commands.task: allow 'task' command with no argument to show cu…
jeffmahoney May 2, 2019
a18e2b7
crash.infra.callbacks: explicitly connect to callbacks
jeffmahoney May 17, 2019
e0fa23e
crash.infra.lookup: move type name resolution into TypeCallback
jeffmahoney May 3, 2019
5dee123
crash.util.symbols: introduce simplified delayed lookups
jeffmahoney May 3, 2019
cc56e25
crash.subsystem.filesystem: add super_flags
jeffmahoney Apr 26, 2019
5f69e54
crash.subsystem.filesystem: add for_each_super_block, get_super_block
jeffmahoney Sep 18, 2018
7d72016
crash.subsystem.filesystem.mount: use type from symbol when available
jeffmahoney Sep 19, 2018
b4facc0
crash.subsystem.filesystem.mount: use crash.util.decode_flags
jeffmahoney May 4, 2019
b2817c9
crash.subsystem.filesystem: include sector number when describing dio…
jeffmahoney May 1, 2019
b7085be
crash.subsystem.{filesystem,storage}: refactor bio decoders
jeffmahoney May 3, 2019
c27620b
crash.types.vmstat: remove dead code
jeffmahoney May 6, 2019
fcb22c4
crash: remove CrashBaseClass
jeffmahoney May 3, 2019
30dd42b
crash.util: add more documentation
jeffmahoney May 20, 2019
65a7e06
crash: factor out task iteration
jeffmahoney May 7, 2019
abfd2dc
crash.commands: handle DelayedAttributeError gracefully
jeffmahoney May 8, 2019
62bb502
crash.commands.dmesg: handling dictionary string encoding better
jeffmahoney May 8, 2019
e7ff8dd
crash.types.slab: improve address printing
jeffmahoney May 9, 2019
6da88b1
crash.commands.kmem: use exceptions to exit command with error
jeffmahoney May 9, 2019
29ea504
crash.commands.kmem: fix argument parsing
jeffmahoney May 9, 2019
f2142e5
crash.commands.kmem: clean up some trivial things
jeffmahoney May 9, 2019
08749dd
crash.commands.ps: uncomment -G mode
jeffmahoney May 10, 2019
004ad94
crash: add kernel testing against vmcores
jeffmahoney May 7, 2019
cfac8fb
crash.types.classdev: update classdev iteration to use device_private
jeffmahoney May 7, 2019
39131e1
crash.subsystem.filesystems: add is_fstype_super and is_fstype_inode
jeffmahoney May 9, 2019
bfd2628
crash.subsystem.filesystem: document gdb.NotAvailableError
jeffmahoney May 15, 2019
c5691bf
crash.subsytem.filesystem.mount: add API documentation
jeffmahoney May 9, 2019
4e60c1c
crash.subsystem.filesystem.btrfs: add helpers for super, inode, and u…
jeffmahoney Apr 29, 2019
7e077de
crash.commands.btrfs: add basic btrfs command
jeffmahoney Sep 18, 2018
575d1ef
crash.subsystem.filesystem.xfs: Add basic XFS infra
jeffmahoney Sep 18, 2018
1522012
crash.commands.xfs: add basic xfs command
jeffmahoney Sep 18, 2018
5483d9f
crash.subsystem.storage.blocksq: add per-queue requests_in_flight call
jeffmahoney Apr 22, 2019
538acd1
crash.commands.lsmod: add basic lsmod command
jeffmahoney May 1, 2019
e7789d4
crash.types.task: get_stack_pointer should take thread_struct
jeffmahoney May 15, 2019
1d22d73
crash.types.task: add accessor-helpers
jeffmahoney May 15, 2019
af12734
crash.commands.ps: factor out formatting
jeffmahoney May 15, 2019
550c337
crash.cache.syscache: update config parsing
jeffmahoney May 9, 2019
d04844b
tests: silence as much noise as possible
jeffmahoney May 17, 2019
cb870bb
crash.util: fix get_typed_pointer semantics
jeffmahoney May 20, 2019
0f70ab1
crash.types.task: add documentation and static typing hints
jeffmahoney May 20, 2019
d6bc98b
crash: more documentation and typing
jeffmahoney May 21, 2019
2834470
WIP: Add initial support for "live" debugging
May 9, 2019
14529d1
WIP: Add new "kcore" target using "drgn" backend
sdimitro May 20, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
WIP: Add new "kcore" target using "drgn" backend
This adds a new "kcore" GDB target which uses "drgn" as the backend for
reading from "/proc/kcore"; very similar to the existing "kdump" target
which uses "kdumpfile" for reading from a crash dump.

The benefit of using this new "kcore" target as opposed to GDB's
existing "core" target is twofold:

 1. The caching done by the "core" target is not what we want when
    inspecting a live, running kernel. By moving to a new python based
    target, we avoid all of this; each read of memory from GDB will call
    into our target, so we have much more control.

 2. The "core" target is unable to properly fetch registers when it's
    used with "/proc/kcore". By using a python target, we can override
    the "fetch_registers" function, and do the right thing for fetching
    registers of kernel threads. Additionally, the code to do this is
    the same for "/proc/kcore" and a kernel crash dump, so the same code
    can be used for both the new "kcore" and existing "kdump" targets.

Unfortunately though, this new "kcore" target does not solve the issue
of thread information being read and cached during startup, meaning we
still do not have "live" thread information when using this new target.

See also: https://github.com/osandov/drgn

Co-authored-by: Prakash Surya <prakash.surya@delphix.com>
  • Loading branch information
sdimitro and Prakash Surya committed May 22, 2019
commit 14529d13cd9117f34e691b0541274dce399010e1
32 changes: 7 additions & 25 deletions crash-kcore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,6 @@ GDBINIT=$(mktemp)
trap "rm '$GDBINIT'" EXIT

VMLINUX="/usr/lib/debug/boot/vmlinux-$(uname -r)"
STEXT_KALLSYMS=$(awk '$3 == "_stext" { print $1 }' /proc/kallsyms)
STEXT_VMLINUX=$(nm "$VMLINUX" | awk '$3 == "_stext" { print $1 }')

#
# Due to the KASLR done by the kernel, the symbol addresses contained in
# the "vmlinux" file are not exactly what's used by the running system.
# To translate the addresses in the "vmlinux" file, to the addresses
# being used on the live system, we have to offset all of the "vmlinux"
# addresses by the KASLR offset. Here we determine the KASLR offset by
# determining the difference between the address of the "_stext" symbol
# as reported by "/proc/kallsyms" and the "vminlinux" file; this offset
# is then later fed into GDB when loading the "vmlinux" symbols.
#
OFFSET=$(python -c "print(int('$STEXT_KALLSYMS', 16) - int('$STEXT_VMLINUX', 16))")

DIR="$(dirname $0)"
if [[ -e "$DIR/setup.py" ]]; then
Expand All @@ -50,22 +36,18 @@ set python print-stack full
set height 0
set print pretty on

add-symbol-file $VMLINUX -o $OFFSET
target core /proc/kcore
python
from kcore.target import Target
target = Target("$VMLINUX", debug=False)
end

#
# Since we're readying from /proc/kcore and the contents of that can
# change, we disable as much of GDB's caching as we can.
#
set stack-cache off
set code-cache off
set dcache size 1
set dcache line-size 2
set non-stop on
target drgn /proc/kcore

python
import crash.session
x = crash.session.Session(None, None, None)
target.unregister()
del target
end
EOF

Expand Down
Empty file added kcore/__init__.py
Empty file.
88 changes: 88 additions & 0 deletions kcore/target.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# -*- coding: utf-8 -*-
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:

import gdb
import drgn
import sys


class Target(gdb.Target):
def __init__(self, vmlinux, debug=False):
super(Target, self).__init__()
self.debug = debug
self.shortname = "drgn"
self.longname = "Use Linux's /proc/kcore as a target through drgn"
self.vmlinux = vmlinux
self.register()

def open(self, filename, from_tty):
if filename != "/proc/kcore":
raise gdb.GdbError("incorrect file target - should be /proc/kcore")

self.drgn = drgn.Program()
self.drgn.set_kernel()

try:
self.drgn.load_default_debug_info()
except drgn.MissingDebugInfoError as e:
print(str(e), file=sys.stderr)

vmcoreinfo = dict(
[
line.split("=")
for line in self.drgn["vmcoreinfo_data"].string_().decode().splitlines()
]
)
offset = int(vmcoreinfo["KERNELOFFSET"], base=16)
gdb.execute("add-symbol-file {} -o {:#x}".format(self.vmlinux, offset))
gdb.execute("file {}".format(self.vmlinux))

def close(self):
try:
self.unregister()
except:
pass
del self.drgn

@classmethod
def report_error(cls, addr, length, error):
print(
"Error while reading {:d} bytes from {:#x}: {}".format(
length, addr, str(error)
),
file=sys.stderr,
)

def xfer_partial(self, obj, annex, readbuf, writebuf, offset, ln):
ret = -1
if obj == self.TARGET_OBJECT_MEMORY:
try:
r = self.drgn.read(offset, ln)
readbuf[:] = r
ret = len(r)
except drgn.FaultError as e:
if self.debug:
self.report_error(offset, ln, e)
raise gdb.TargetXferUnavailable(str(e))
else:
raise IOError("Unknown obj type")
return ret

def thread_alive(self, ptid):
return True

def pid_to_str(self, ptid):
return "pid {:d}".format(ptid[1])

def fetch_registers(self, register):
return False

def prepare_to_store(self, thread):
pass

# We don't need to store anything; The regcache is already written.
def store_registers(self, thread):
pass

def has_execution(self, ptid):
return False