<commit_before>try:
    import logging
    blessed = None
    import blessed

    import voltron
    from voltron.core import Server
    from voltron.plugin import PluginManager
    try:
        import lldb
        in_lldb = True
    except ImportError:
        in_lldb = False
    try:
        import gdb
        in_gdb = True
    except ImportError:
        in_gdb = False

    if "vtrace" in locals():
        in_vdb = True

        import os
        import sys

        def parent_directory(the_path):
            return os.path.abspath(os.path.join(the_path, os.pardir))

        def add_vdb_to_path(vtrace):
            sys.path.append(parent_directory(parent_directory(vtrace.__file__)))

        # don't pass over this line!
        # in order for the *VDB adaptor plugin* (not this file) to import
        #  vdb stuff, the import path must be updated.
        # this is it.
        #
        # since atm vdb imports everything relatively
        #   (typically its not installed), then we use this
        #   hack to extract the package that's in use.
        add_vdb_to_path(vtrace)
        import vtrace
    else:
        in_vdb = False

    log = voltron.setup_logging('debugger')

    class VoltronCommand (object):
        """
        Parent class for common methods across all debugger hosts.
        """
        def handle_command(self, command):
            global log
            if "status" in command:
                self.status()
            elif 'debug' in command:
                if 'enable' in command:
                    log.setLevel(logging.DEBUG)
                    print("Debug logging enabled")
                elif 'disable' in command:
                    log.setLevel(logging.INFO)
                    print("Debug logging disabled")
                else:
                    enabled = "enabled" if log.getEffectiveLevel() == logging.DEBUG else "disabled"
                    print("Debug logging is currently " + enabled)
            elif 'init' in command:
                self.register_hooks()
            elif 'stopped' in command or 'update' in command:
                self.adaptor.update_state()
                self.server.dispatch_queue()
            else:
                print("Usage: voltron <init|status|debug|update>")

        def status(self):
            if self.server is not None:
                summs = self.server.client_summary()
                print("The following listeners are active:")
                listen = voltron.config['server']['listen']
                if listen['domain']:
                    print("  domain socket ({})".format(voltron.env['sock']))
                if listen['tcp']:
                    print("  TCP socket ({})".format(listen['tcp']))
                if listen['http']:
                    print("  web server ({})".format(listen['http']))
                print("There are {} clients attached:".format(len(summs)))
                for summary in summs:
                    print("  " + summary)
            else:
                print("Server is not running (no inferior)")

    if in_lldb:
        class VoltronLLDBCommand (VoltronCommand):
            """
            Debugger command class for LLDB
            """
            def __init__(self, debugger, dict):
                super(VoltronCommand, self).__init__()

                # grab the debugger and command interpreter
                self.debugger = debugger
                self.ci = self.debugger.GetCommandInterpreter()

                # install the voltron command handler
                self.debugger.HandleCommand('command script add -f dbgentry.lldb_invoke voltron')

                # load plugins
                self.pm = voltron.plugin.pm

                # set up an lldb adaptor and set it as the package-wide adaptor
                self.adaptor = self.pm.debugger_plugin_for_host('lldb').adaptor_class()
                voltron.debugger = self.adaptor

                # register plugins now that we have a debugger
                self.pm.register_plugins()

                # start the server
                self.server = Server()
                self.server.start()

                self.hook_idx = None

            def invoke(self, debugger, command, result, dict):
                self.handle_command(command)

            def register_hooks(self):
                try:
                    output = self.adaptor.command("target stop-hook list")
                    if 'voltron' not in output:
                        output = self.adaptor.command('target stop-hook add -o \'voltron stopped\'')
                        try:
                            # hahaha this sucks
                            self.hook_idx = int(res.GetOutput().strip().split()[2][1:])
                        except:
                            pass
                    print("Registered stop-hook")
                except:
                    print("No targets")

            def unregister_hooks(self):
                cmd = 'target stop-hook delete {}'.format(self.hook_idx if self.hook_idx else '')
                self.debugger.HandleCommand(cmd)

        def __lldb_init_module(debugger, env_dict):
            """
            Called by LLDB when the module is loaded
            """
            if 'cmd' not in env_dict:<commit_msg>Store server reference for debugging<commit_after>try:
    import logging
    blessed = None
    import blessed

    import voltron
    from voltron.core import Server
    from voltron.plugin import PluginManager
    try:
        import lldb
        in_lldb = True
    except ImportError:
        in_lldb = False
    try:
        import gdb
        in_gdb = True
    except ImportError:
        in_gdb = False

    if "vtrace" in locals():
        in_vdb = True

        import os
        import sys

        def parent_directory(the_path):
            return os.path.abspath(os.path.join(the_path, os.pardir))

        def add_vdb_to_path(vtrace):
            sys.path.append(parent_directory(parent_directory(vtrace.__file__)))

        # don't pass over this line!
        # in order for the *VDB adaptor plugin* (not this file) to import
        #  vdb stuff, the import path must be updated.
        # this is it.
        #
        # since atm vdb imports everything relatively
        #   (typically its not installed), then we use this
        #   hack to extract the package that's in use.
        add_vdb_to_path(vtrace)
        import vtrace
    else:
        in_vdb = False

    log = voltron.setup_logging('debugger')

    class VoltronCommand (object):
        """
        Parent class for common methods across all debugger hosts.
        """
        def handle_command(self, command):
            global log
            if "status" in command:
                self.status()
            elif 'debug' in command:
                if 'enable' in command:
                    log.setLevel(logging.DEBUG)
                    print("Debug logging enabled")
                elif 'disable' in command:
                    log.setLevel(logging.INFO)
                    print("Debug logging disabled")
                else:
                    enabled = "enabled" if log.getEffectiveLevel() == logging.DEBUG else "disabled"
                    print("Debug logging is currently " + enabled)
            elif 'init' in command:
                self.register_hooks()
            elif 'stopped' in command or 'update' in command:
                self.adaptor.update_state()
                self.server.dispatch_queue()
            else:
                print("Usage: voltron <init|status|debug|update>")

        def status(self):
            if self.server is not None:
                summs = self.server.client_summary()
                print("The following listeners are active:")
                listen = voltron.config['server']['listen']
                if listen['domain']:
                    print("  domain socket ({})".format(voltron.env['sock']))
                if listen['tcp']:
                    print("  TCP socket ({})".format(listen['tcp']))
                if listen['http']:
                    print("  web server ({})".format(listen['http']))
                print("There are {} clients attached:".format(len(summs)))
                for summary in summs:
                    print("  " + summary)
            else:
                print("Server is not running (no inferior)")

    if in_lldb:
        class VoltronLLDBCommand (VoltronCommand):
            """
            Debugger command class for LLDB
            """
            def __init__(self, debugger, dict):
                super(VoltronCommand, self).__init__()

                # grab the debugger and command interpreter
                self.debugger = debugger
                self.ci = self.debugger.GetCommandInterpreter()

                # install the voltron command handler
                self.debugger.HandleCommand('command script add -f dbgentry.lldb_invoke voltron')

                # load plugins
                self.pm = voltron.plugin.pm

                # set up an lldb adaptor and set it as the package-wide adaptor
                self.adaptor = self.pm.debugger_plugin_for_host('lldb').adaptor_class()
                voltron.debugger = self.adaptor

                # register plugins now that we have a debugger
                self.pm.register_plugins()

                # start the server
                self.server = Server()
                self.server.start()
                voltron.server = self.server

                self.hook_idx = None

            def invoke(self, debugger, command, result, dict):
                self.handle_command(command)

            def register_hooks(self):
                try:
                    output = self.adaptor.command("target stop-hook list")
                    if 'voltron' not in output:
                        output = self.adaptor.command('target stop-hook add -o \'voltron stopped\'')
                        try:
                            # hahaha this sucks
                            self.hook_idx = int(res.GetOutput().strip().split()[2][1:])
                        except:
                            pass
                    print("Registered stop-hook")
                except:
                    print("No targets")

            def unregister_hooks(self):
                cmd = 'target stop-hook delete {}'.format(self.hook_idx if self.hook_idx else '')
                self.debugger.HandleCommand(cmd)

        def __lldb_init_module(debugger, env_dict):
            """
            Called by LLDB when the module is loaded
            """
            if 'cmd' not in env_dict:
{'fraction_non_alphanumeric': 0.08639774859287054, 'fraction_numerical': 0.000375234521575985, 'mean_word_length': 1.4746982358402971, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2424378', 'n_tokens_mistral': 2816, 'n_tokens_neox': 2614, 'n_words': 757}