ProfilerBreakpoint.py 2.26 KB
Newer Older
German Leon's avatar
German Leon committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import traceback

import gdb
import common_functions as cf  # All common functions will be at common_functions module
import common_parameters as cp  # All common parameters will be at common_parameters module

"""
ProfilerBreakpoint class
will manager the breakpoint event when gdb stops
"""


class ProfilerBreakpoint(gdb.Breakpoint):
    def __init__(self, *args, **kwargs):
        if cp.DEBUG_PROFILER:
            print("IT IS IN __INIT__ METHOD")
        self.__kludge = kwargs.pop('kludge') if 'kludge' in kwargs else False
        self.__kernel_name = kwargs.pop('kernel_name') if 'kernel_name' in kwargs else None
        self.__kernel_line = kwargs.pop('kernel_line') if 'kernel_line' in kwargs else None
        self.__kernel_end_line = kwargs.pop('kernel_end_line') if 'kernel_end_line' in kwargs else None
        self.__addresses = None
        self.__kernel_line = kwargs.get('spec')

        super(ProfilerBreakpoint, self).__init__(*args, **kwargs)

    def stop(self):
        if cp.DEBUG_PROFILER:
            print("IT IS IN STOP METHOD")
        if self.__kludge:
            return True

        print("FOUND A KERNEL LINE {}".format(self.__kernel_line))
        self.__generate_source_ass_list()
        kernel_info = {
            'addresses': self.__addresses,
            'kernel_name': self.__kernel_name,
            'kernel_line': self.__kernel_line,
            'kernel_end_line': self.__kernel_end_line
        }

        cf.append_file(file_path=cp.KERNEL_INFO_DIR, data=kernel_info)

    """
    inject faults only on the resources used at that source line
    """

    def __generate_source_ass_list(self):
        source_list = []
        assemble_lines = []
        disassemble_gdb = cf.execute_command(gdb, "disassemble /m")
        for l in disassemble_gdb:
            if '0x' in l:
                assemble_lines.append(l)
            else:
                source_list.append([[l], assemble_lines[:]])
                assemble_lines = []

        last_not_zero_size = None
        self.__addresses = []
        for l, ass_line in source_list:
            # I have to merge with
            if len(ass_line) is not 0:
                last_not_zero_size = l
                self.__addresses.append([l, ass_line])
            else:
                last_not_zero_size.append(l)