예제 #1
0
 def _check_vmcore(self, filename):
     '''
     Will create a VMCore object from a given core file
     or throw an exception if crash has a problem inspecting the
     core file for OSRELEASE.
     '''
     self.vmcore = VMCore(filename)
예제 #2
0
class BTExtract(InteractivePlugin):
    plugin_name = 'btextract'
    _submenu_opts = None
    _sections = None
    end_of_entries = ''
    vmcore = None
    mkdumpfilepath = None
    # Should interactive_plugin/non_interactive_plugin skip output methods?
    no_submenu = False

    @classmethod
    def get_usage(cls):
        '''
        The usage statement that will be printed by OptionParser.

        Example:
            - %prog -c CASENUMBER [options] <comment text here>
        Important: %prog is a OptionParser built-in.  Use it!
        '''
        return _('%prog [options] </path/to/vmcore>')

    @classmethod
    def get_desc(cls):
        '''
        The description statement that will be printed by OptionParser.

        Example:
            - 'Use the \'%s\' command to add a comment to a case.'\
             % cls.plugin_name
        '''
        return _('Use the \'%s\' command get a kernel stack backtrace and '
                 'other related information from a kernel core dump file. '
                 'The default behavior is to issue \'bt -a\'; however, there '
                 'are a variety of other \'crash\' '
                 'commands that can be run.') % cls.plugin_name

    @classmethod
    def get_epilog(cls):
        '''
        The epilog string that will be printed by OptionParser.  Usually
        used to print an example of how to use the program.

        Example:
         Examples:
          - %s -c 12345678 Lorem ipsum dolor sit amet, consectetur adipisicing
          - %s -c 12345678
        '''
        return _("""Examples:
  - %s /var/crash/vmcore""") \
  % (cls.plugin_name)

    @classmethod
    def get_options(cls):
        '''
        Subclasses that need command line options should override this method
        and return an array of optparse.Option(s) to be used by the
        OptionParser.

        Example:
         return [Option("-f", "--file", action="store",
                        dest="filename", help='Some file'),
                 Option("-c", "--case",
                        action="store", dest="casenumber",
                        help='A case')]

         Would produce the following:
         Command (? for help): help mycommand

         Usage: mycommand [options]

         Use the 'mycommand' command to find a knowledge base solution by ID
         Options:
           -h, --help  show this help message and exit
           -f, --file  Some file
           -c, --case  A case
         Example:
          - mycommand -c 12345 -f abc.txt

        '''
        return [
            Option('-c',
                   '--case',
                   dest='casenumber',
                   help=_('Add the collected data as a comment to the '
                          'provided case.'),
                   default=None),
            Option("-a",
                   "--all",
                   dest="all",
                   action="store_true",
                   help=_('Run all options. Equals -aeflpFi'),
                   default=False),
            Option("-e",
                   "--exframe",
                   dest="exframe",
                   action="store_true",
                   help=_('Search the stack for possible kernel and user '
                          'mode exception frames (ie. bt -e).'),
                   default=False),
            Option("-f",
                   "--foreachbt",
                   dest="foreachbt",
                   action="store_true",
                   help=_('Display the stack traces for all tasks '
                          '(ie. foreach bt).'),
                   default=False),
            Option("-l",
                   "--log",
                   dest="log",
                   action="store_true",
                   help=_('Dumps the kernel log_buf contents in '
                          'chronological order.'),
                   default=False),
            Option("-p",
                   "--ps",
                   dest="ps",
                   action="store_true",
                   help=_('Displays process status for selected processes '
                          'in the system.'),
                   default=False),
            Option("-F",
                   "--files",
                   dest="files",
                   action="store_true",
                   help=_('Displays information about open files.'),
                   default=False),
            Option("-i",
                   "--cmdfile",
                   dest="cmdfile",
                   help=_('Run a sequence of individual \'crash\' commands '
                          'from a file.'),
                   default=None)
        ]

    def get_intro_text(self):
        return _('\nSelect the crash command output to view or \'e\' '
                 'to return to the previous menu.')

    def get_sub_menu_options(self):
        return self._submenu_opts

    def _check_vmcore(self, filename):
        '''
        Will create a VMCore object from a given core file
        or throw an exception if crash has a problem inspecting the
        core file for OSRELEASE.
        '''
        self.vmcore = VMCore(filename)

    def _find_debug_symbols(self):
        '''
        At this point self.vmcore had better be non-null.  This
        method will call vmcorehelper's get_debug_symbols which scans
        the designated debug symbols directory looking for debug symbols
        which match the given core file.  If symbols are found, the
        VMCore object will be passed a VMLinux object.
        '''
        kernelext_dir = confighelper.get_config_helper().get(
            option='kern_debug_dir')
        vmlinux = vmcorehelper.get_debug_symbols(
            kernelext_dir, self.vmcore.getKernelVersion())
        if vmlinux:
            self.vmcore.setDebugSymbols(vmlinux)
        else:
            print _('WARNING: Debug symbols for %s were not found.') % \
                    self._args[0]
            line = raw_input(_('Would you like to install kernel-debuginfo-%s '
                    'from available debug repositories (y/n)? ') % \
                    self.vmcore.getKernelVersion())
            if str(line).strip().lower() == 'y':
                print _('Installing kernel-debuginfo-%s') % \
                    self.vmcore.getKernelVersion()
                lh = LaunchHelper(GetKernelDebugPackages)
                lh.run(self.vmcore.getKernelVersion(), pt_exception=True)
                vmlinux = vmcorehelper.get_debug_symbols(
                    kernelext_dir, self.vmcore.getKernelVersion())
                if vmlinux:
                    self.vmcore.setDebugSymbols(vmlinux)
                else:
                    raise Exception(
                        _('Installation of debug images failed, '
                          'cannot proceed with debug session'))
            else:
                raise Exception('User elected not to install debug '
                                'packages for kernel-debuginfo-%s' % \
                                self.vmcore.getKernelVersion())

    def validate_args(self):
        if not self._args:
            msg = _('ERROR: %s requires the full path to a kernel core dump '
                    'file.') % self.plugin_name
            print msg
            raise Exception(msg)
        self._check_vmcore(self._args[0])
        try:
            self._find_debug_symbols()
        except Exception, e:
            logger.log(logging.DEBUG, e)
            if os.path.exists('/usr/sbin/makedumpfile'):
                self.mkdumpfilepath = '/usr/sbin/makedumpfile'
            elif os.path.exists('/sbin/makedumpfile'):
                self.mkdumpfilepath = '/sbin/makedumpfile'
            else:
                raise