コード例 #1
0
    def run(self):
        """
        Starts a REPL session.
        """
        while True:
            try:
                line = input(self.prompt).strip()
                if not line:
                    continue

                objs = sdb.invoke(self.target, [], line)
                if not objs:
                    continue

                for obj in objs:
                    print(obj)

            except sdb.CommandArgumentsError:
                #
                # We skip printing anything for this specific error
                # as argparse should have already printed a helpful
                # message to the REPL for us.
                #
                continue
            except sdb.Error as err:
                print(err.text)
            except (EOFError, KeyboardInterrupt):
                print(self.closing)
                break
コード例 #2
0
ファイル: __init__.py プロジェクト: prashks/sdb-old
def invoke(prog: drgn.Program, objs: Iterable[drgn.Object],
           line: str) -> Iterable[drgn.Object]:
    """
    Dispatch to sdb.invoke, but also drain the generator it returns, so
    the tests can more easily access the returned objects.
    """
    return [i for i in sdb.invoke(prog, objs, line)]
コード例 #3
0
ファイル: repl.py プロジェクト: sukidoke/sdb
    def eval_cmd(self, input_: str) -> int:
        """
        Evaluates the SDB command/pipeline passed as input_
        and prints the result.

        Returns:
            0 for success
            1 for error
            2 for incorrect arguments passed
        """
        try:
            objs = sdb.invoke(self.target, [], input_)
            if not objs:
                return 0

            for obj in objs:
                print(obj)
        except sdb.CommandArgumentsError:
            #
            # We skip printing anything for this specific error
            # as argparse should have already printed a helpful
            # message to the REPL for us.
            #
            return 2
        except sdb.Error as err:
            print(err.text)
            return 1
        return 0
コード例 #4
0
ファイル: infra.py プロジェクト: sravyamks/sdb
def sdb_invoke(objs: Iterable[drgn.Object],
               line: str) -> Iterable[drgn.Object]:
    """
    Dispatch to sdb.invoke, but also drain the generator it returns, so
    the tests can more easily access the returned objects.

    This method is preferred over repl_invoke() when the test wants to
    do fancier checks by mocking a few objects that are later passed
    down to the pipeline. Other scenarios include but are not limited
    to testing that specific exceptions are thrown or analyzing internal
    state of objects that is not part of the output in stdout.
    """
    assert TEST_PROGRAM
    return list(sdb.invoke(TEST_PROGRAM, objs, line))