Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions 7 crash/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
#!/usr/bin/env python
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:

import kdump.target

class Session:
def __init__(self, filename):
self.target = kdump.target.Target(filename)
import crash.commands
46 changes: 46 additions & 0 deletions 46 crash/arch/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env python
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:

import os
import glob
import importlib

class CrashArchitecture:
ident = "base-class"
aliases = None
def __init__(self):
pass

def setup_thread_active(self, thread):
raise NotImplementedError("setup_thread_active not implemented")

def setup_thread_scheduled(self, thread):
raise NotImplementedError("setup_thread_scheduled not implemented")

def setup_thread_info(self, thread):
raise NotImplementedError("setup_thread_info not implemented")

def setup_thread(self, thread):
if thread.info.active:
self.setup_thread_active(thread)
else:
self.setup_thread_scheduled(thread)

architectures = {}
def register(arch):
architectures[arch.ident] = arch
for ident in arch.aliases:
architectures[ident] = arch

def get_architecture(archname):
if archname in architectures:
return architectures[archname]

return None

modules = glob.glob(os.path.dirname(__file__)+"/[A-Za-z]*.py")
__all__ = [ os.path.basename(f)[:-3] for f in modules]

mods = __all__
for mod in mods:
x = importlib.import_module("crash.arch.%s" % mod)
66 changes: 66 additions & 0 deletions 66 crash/arch/x86_64.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env python
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:

import gdb
from crash.arch import CrashArchitecture, register

class x86_64Architecture(CrashArchitecture):
ident = "i386:x86-64"
aliases = [ "x86_64" ]

def __init__(self):
# PC for blocked threads
self.rip = gdb.lookup_minimal_symbol("thread_return").value()
self.ulong_type = gdb.lookup_type('unsigned long')
thread_info_type = gdb.lookup_type('struct thread_info')
self.thread_info_p_type = thread_info_type.pointer()

def setup_thread_info(self, thread):
task = thread.info.task_struct
thread_info = task['stack'].cast(self.thread_info_p_type)
thread.info.set_thread_info(thread_info)

def setup_thread_active(self, thread):
task = thread.info
for reg in task.regs:
if reg in ["gs_base", "orig_ax", "rflags", "fs_base"]:
continue
thread.registers[reg].value = task.regs[reg]

def setup_thread_scheduled(self, thread):
ulong_type = self.ulong_type
task = thread.info.task_struct

rsp = task['thread']['sp'].cast(ulong_type.pointer())
rbp = rsp.dereference().cast(ulong_type.pointer())
rbx = (rbp - 1).dereference()
r12 = (rbp - 2).dereference()
r13 = (rbp - 3).dereference()
r14 = (rbp - 4).dereference()
r15 = (rbp - 5).dereference()

# The two pushes that don't have CFI info
# rsp += 2

# ex = in_exception_stack(rsp)
# if ex:
# print "EXCEPTION STACK: pid %d" % task['pid']

thread.registers['rsp'].value = rsp
thread.registers['rbp'].value = rbp
thread.registers['rip'].value = self.rip
thread.registers['rbx'].value = rbx
thread.registers['r12'].value = r12
thread.registers['r13'].value = r13
thread.registers['r14'].value = r14
thread.registers['r15'].value = r15
thread.registers['cs'].value = 2*8
thread.registers['ss'].value = 3*8

thread.info.stack_pointer = rsp
thread.info.valid_stack = True

def get_stack_pointer(self, thread):
return long(thread.registers['rsp'].value)

register(x86_64Architecture)
25 changes: 25 additions & 0 deletions 25 crash/cache/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env python
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:

import gdb

import os
import glob
import importlib

class CrashCache(object):
def __init__(self):
pass

def refresh(self):
pass

def needs_updating(self):
return False

modules = glob.glob(os.path.dirname(__file__)+"/[A-Za-z]*.py")
__all__ = [ os.path.basename(f)[:-3] for f in modules]

mods = __all__
for mod in mods:
x = importlib.import_module("crash.cache.%s" % mod)
14 changes: 14 additions & 0 deletions 14 crash/cache/vm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env python
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:

import gdb

from crash.cache import CrashCache
class CrashCacheVM(CrashCache):
def __init__(self):
super(CrashCacheVM, self).__init__()

def refresh(self):
pass

cache = CrashCacheVM()
31 changes: 31 additions & 0 deletions 31 crash/commands/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env python
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:

import gdb

import os
import glob
import importlib

class CrashCommand(gdb.Command):
def __init__(self, name, parser):
gdb.Command.__init__(self, "py" + name, gdb.COMMAND_USER)
parser.format_help = lambda: self.__doc__
self.parser = parser

def invoke(self, argstr, from_tty):
argv = gdb.string_to_argv(argstr)
try:
args = self.parser.parse_args(argv)
self.execute(args)
except SystemExit:
return
except KeyboardInterrupt:
return

modules = glob.glob(os.path.dirname(__file__)+"/[A-Za-z]*.py")
__all__ = [ os.path.basename(f)[:-3] for f in modules]

mods = __all__
for mod in mods:
x = importlib.import_module("crash.commands.%s" % mod)
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.