Exemplo n.º 1
0
 def get_avg_time_to_parse(self, input_str, num_runs):
     avg_time = 0
     for _ in range(num_runs):
         t0 = time()
         parse_response(input_str)
         t1 = time()
         time_to_run = t1 - t0
         avg_time += time_to_run / num_runs
     return avg_time
Exemplo n.º 2
0
    def _get_responses_list(self, raw_output, stream):
        """Get parsed response list from string output
        Args:
            raw_output (unicode): gdb output to parse
            stream (str): either stdout or stderr
        """
        responses = []

        raw_output, self._incomplete_output[stream] = _buffer_incomplete_responses(
            raw_output, self._incomplete_output.get(stream)
        )

        if not raw_output:
            return responses

        response_list = list(
            filter(lambda x: x, raw_output.decode(errors="replace").split("\n"))
        )  # remove blank lines

        # parse each response from gdb into a dict, and store in a list
        for response in response_list:
            if gdbmiparser.response_is_finished(response):
                pass
            else:
                parsed_response = gdbmiparser.parse_response(response)
                parsed_response["stream"] = stream

                self.logger.debug("%s", pformat(parsed_response))

                responses.append(parsed_response)

        return responses
Exemplo n.º 3
0
    def _get_responses_list(self, raw_output, stream, verbose):
        """Get parsed response list from string output
        Args:
            raw_output (unicode): gdb output to parse
            stream (str): either stdout or stderr
            verbose (bool): add verbose output when true
        """
        responses = []

        raw_output, self._incomplete_output[
            stream] = _buffer_incomplete_responses(
                raw_output, self._incomplete_output.get(stream))

        if not raw_output:
            return responses

        response_list = list(
            filter(lambda x: x,
                   raw_output.decode().split('\n')))  # remove blank lines

        # parse each response from gdb into a dict, and store in a list
        for response in response_list:
            if gdbmiparser.response_is_finished(response):
                pass
            else:
                parsed_response = gdbmiparser.parse_response(response)
                parsed_response['stream'] = stream

                responses.append(parsed_response)
                if verbose:
                    pprint(parsed_response)

        return responses
Exemplo n.º 4
0
    def _get_responses_list(self, raw_output, stream, verbose):
        """Get parsed response list from string output
        Args:
            raw_output (unicode): gdb output to parse
            stream (str): either stdout or stderr
            verbose (bool): add verbose output when true
        """
        responses = []
        if not raw_output:
            return responses

        stripped_raw_response_list = [
            x.strip() for x in raw_output.decode().split('\n')
        ]
        raw_response_list = list(
            filter(lambda x: x, stripped_raw_response_list))
        raw_response_list, self._buffer = _buffer_incomplete_responses(
            raw_response_list, self._buffer)

        # parse each response from gdb and put into a list
        for response in raw_response_list:
            if gdbmiparser.response_is_finished(response):
                pass
            else:
                parsed_response = gdbmiparser.parse_response(response)
                parsed_response['stream'] = stream

                responses.append(parsed_response)
                if verbose:
                    pprint(parsed_response)
        return responses
Exemplo n.º 5
0
def parse_response(response, line_num=0):
    """Parses the given GDB/MI output. Wraps gdbmiparser.parse_response
    GDB_Engine.send_command returns an additional "^done" output because of the "source" command
    This function is used to get rid of that output before parsing

    Args:
        response (str): GDB/MI response
        line_num (int): Which line of the response will be parsed

    Returns:
        dict: Contents of the dict depends on the response
    """
    return gdbmiparser.parse_response(response.splitlines()[line_num])
Exemplo n.º 6
0
    def test_parser(self):
        """Test that the parser returns dictionaries from gdb mi strings as expected"""

        # Test basic types
        assert_match(parse_response('^done'), {
            'type': 'result',
            'payload': None,
            'message': 'done',
            "token": None
        })
        assert_match(parse_response('~"done"'), {
            'type': 'console',
            'payload': 'done',
            'message': None
        })
        assert_match(parse_response('@"done"'), {
            "type": 'target',
            "payload": 'done',
            'message': None
        })
        assert_match(parse_response('&"done"'), {
            "type": 'log',
            "payload": 'done',
            'message': None
        })
        assert_match(parse_response('done'), {
            'type': 'output',
            'payload': 'done',
            'message': None
        })

        # Test escape sequences
        assert_match(parse_response('~""'), {
            "type": "console",
            "payload": "",
            'message': None
        })
        assert_match(parse_response('~"\b\f\n\r\t\""'), {
            "type": "console",
            "payload": '\b\f\n\r\t\"',
            'message': None
        })
        assert_match(parse_response('@""'), {
            "type": "target",
            "payload": "",
            'message': None
        })
        assert_match(parse_response('@"\b\f\n\r\t\""'), {
            "type": "target",
            "payload": '\b\f\n\r\t\"',
            'message': None
        })
        assert_match(parse_response('&""'), {
            "type": "log",
            "payload": "",
            'message': None
        })
        assert_match(parse_response('&"\b\f\n\r\t\""'), {
            "type": "log",
            "payload": '\b\f\n\r\t\"',
            'message': None
        })

        # Test that a dictionary with repeated keys (a gdb bug) is gracefully worked-around  by pygdbmi
        # See https://sourceware.org/bugzilla/show_bug.cgi?id=22217
        # and https://github.com/cs01/pygdbmi/issues/19
        assert_match(
            parse_response(
                '^done,thread-ids={thread-id="3",thread-id="2",thread-id="1"}, current-thread-id="1",number-of-threads="3"'
            ), {
                "type": "result",
                "payload": {
                    'thread-ids': {
                        'thread-id': ['3', '2', '1']
                    },
                    'current-thread-id': '1',
                    'number-of-threads': '3',
                },
                'message': 'done',
                'token': None
            })

        # Test a real world Dictionary
        assert_match(
            parse_response(
                '=breakpoint-modified,bkpt={number="1",empty_arr=[],type="breakpoint",disp="keep",enabled="y",addr="0x000000000040059c",func="main",file="hello.c",fullname="/home/git/pygdbmi/tests/sample_c_app/hello.c",line="9",thread-groups=["i1"],times="1",original-location="hello.c:9"}'
            ), {
                'message': 'breakpoint-modified',
                'payload': {
                    'bkpt': {
                        'addr': '0x000000000040059c',
                        'disp': 'keep',
                        'enabled': 'y',
                        'file': 'hello.c',
                        'fullname':
                        '/home/git/pygdbmi/tests/sample_c_app/hello.c',
                        'func': 'main',
                        'line': '9',
                        'number': '1',
                        'empty_arr': [],
                        'original-location': 'hello.c:9',
                        'thread-groups': ['i1'],
                        'times': '1',
                        'type': 'breakpoint'
                    }
                },
                'type': 'notify',
                'token': None
            })

        # Test records with token
        assert_match(parse_response('1342^done'), {
            'type': 'result',
            'payload': None,
            'message': 'done',
            "token": 1342
        })
Exemplo n.º 7
0
    def test_parser(self):
        """Test that the parser returns dictionaries from gdb mi strings as expected"""

        # Test basic types
        assert_match(
            parse_response("^done"),
            {
                "type": "result",
                "payload": None,
                "message": "done",
                "token": None
            },
        )
        assert_match(
            parse_response('~"done"'),
            {
                "type": "console",
                "payload": "done",
                "message": None
            },
        )
        assert_match(
            parse_response('@"done"'),
            {
                "type": "target",
                "payload": "done",
                "message": None
            },
        )
        assert_match(
            parse_response('&"done"'),
            {
                "type": "log",
                "payload": "done",
                "message": None
            },
        )
        assert_match(
            parse_response("done"),
            {
                "type": "output",
                "payload": "done",
                "message": None
            },
        )

        # Test escape sequences
        assert_match(parse_response('~""'), {
            "type": "console",
            "payload": "",
            "message": None
        })
        assert_match(
            parse_response('~"\b\f\n\r\t""'),
            {
                "type": "console",
                "payload": '\b\f\n\r\t"',
                "message": None
            },
        )
        assert_match(parse_response('@""'), {
            "type": "target",
            "payload": "",
            "message": None
        })
        assert_match(
            parse_response('@"\b\f\n\r\t""'),
            {
                "type": "target",
                "payload": '\b\f\n\r\t"',
                "message": None
            },
        )
        assert_match(parse_response('&""'), {
            "type": "log",
            "payload": "",
            "message": None
        })
        assert_match(
            parse_response('&"\b\f\n\r\t""'),
            {
                "type": "log",
                "payload": '\b\f\n\r\t"',
                "message": None
            },
        )
        assert_match(parse_response('&"\\"'), {
            "type": "log",
            "payload": "\\",
            "message": None
        })  # test that an escaped backslash gets captured

        # Test that a dictionary with repeated keys (a gdb bug) is gracefully worked-around  by pygdbmi
        # See https://sourceware.org/bugzilla/show_bug.cgi?id=22217
        # and https://github.com/cs01/pygdbmi/issues/19
        assert_match(
            parse_response(
                '^done,thread-ids={thread-id="3",thread-id="2",thread-id="1"}, current-thread-id="1",number-of-threads="3"'
            ),
            {
                "type": "result",
                "payload": {
                    "thread-ids": {
                        "thread-id": ["3", "2", "1"]
                    },
                    "current-thread-id": "1",
                    "number-of-threads": "3",
                },
                "message": "done",
                "token": None,
            },
        )

        # Test a real world Dictionary
        assert_match(
            parse_response(
                '=breakpoint-modified,bkpt={number="1",empty_arr=[],type="breakpoint",disp="keep",enabled="y",addr="0x000000000040059c",func="main",file="hello.c",fullname="/home/git/pygdbmi/tests/sample_c_app/hello.c",line="9",thread-groups=["i1"],times="1",original-location="hello.c:9"}'
            ),
            {
                "message": "breakpoint-modified",
                "payload": {
                    "bkpt": {
                        "addr": "0x000000000040059c",
                        "disp": "keep",
                        "enabled": "y",
                        "file": "hello.c",
                        "fullname":
                        "/home/git/pygdbmi/tests/sample_c_app/hello.c",
                        "func": "main",
                        "line": "9",
                        "number": "1",
                        "empty_arr": [],
                        "original-location": "hello.c:9",
                        "thread-groups": ["i1"],
                        "times": "1",
                        "type": "breakpoint",
                    }
                },
                "type": "notify",
                "token": None,
            },
        )

        # Test records with token
        assert_match(
            parse_response("1342^done"),
            {
                "type": "result",
                "payload": None,
                "message": "done",
                "token": 1342
            },
        )

        # Test extra characters at end of dictionary are discarded (issue #30)
        assert_match(
            parse_response('=event,name="gdb"discardme'),
            {
                "type": "notify",
                "payload": {
                    "name": "gdb"
                },
                "message": "event",
                "token": None,
            },
        )
Exemplo n.º 8
0
    def test_parser(self):
        """Test that the parser returns dictionaries from gdb mi strings as expected"""

        # Test basic types
        assert_match(parse_response('^done'), {
            'type': 'result',
            'payload': None,
            'message': 'done',
            "token": None
        })
        assert_match(parse_response('~"done"'), {
            'type': 'console',
            'payload': 'done',
            'message': None
        })
        assert_match(parse_response('@"done"'), {
            "type": 'target',
            "payload": 'done',
            'message': None
        })
        assert_match(parse_response('&"done"'), {
            "type": 'log',
            "payload": 'done',
            'message': None
        })
        assert_match(parse_response('done'), {
            'type': 'output',
            'payload': 'done',
            'message': None
        })

        # Test escape sequences
        assert_match(parse_response('~""'), {
            "type": "console",
            "payload": "",
            'message': None
        })
        assert_match(parse_response('~"\b\f\n\r\t\""'), {
            "type": "console",
            "payload": '\b\f\n\r\t\"',
            'message': None
        })
        assert_match(parse_response('@""'), {
            "type": "target",
            "payload": "",
            'message': None
        })
        assert_match(parse_response('@"\b\f\n\r\t\""'), {
            "type": "target",
            "payload": '\b\f\n\r\t\"',
            'message': None
        })
        assert_match(parse_response('&""'), {
            "type": "log",
            "payload": "",
            'message': None
        })
        assert_match(parse_response('&"\b\f\n\r\t\""'), {
            "type": "log",
            "payload": '\b\f\n\r\t\"',
            'message': None
        })

        # Test a real world Dictionary
        assert_match(
            parse_response(
                '=breakpoint-modified,bkpt={number="1",empty_arr=[],type="breakpoint",disp="keep",enabled="y",addr="0x000000000040059c",func="main",file="hello.c",fullname="/home/git/pygdbmi/tests/sample_c_app/hello.c",line="9",thread-groups=["i1"],times="1",original-location="hello.c:9"}'
            ), {
                'message': 'breakpoint-modified',
                'payload': {
                    'bkpt': {
                        'addr': '0x000000000040059c',
                        'disp': 'keep',
                        'enabled': 'y',
                        'file': 'hello.c',
                        'fullname':
                        '/home/git/pygdbmi/tests/sample_c_app/hello.c',
                        'func': 'main',
                        'line': '9',
                        'number': '1',
                        'empty_arr': [],
                        'original-location': 'hello.c:9',
                        'thread-groups': ['i1'],
                        'times': '1',
                        'type': 'breakpoint'
                    }
                },
                'type': 'notify',
                'token': None
            })

        #Test records with token
        assert_match(parse_response('1342^done'), {
            'type': 'result',
            'payload': None,
            'message': 'done',
            "token": 1342
        })