<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def evaluate(self, frame_id, expression, global_context=False, disable_break=False):
 """Evaluates 'expression' in the context of the frame identified by 'frame_id' or globally. Breakpoints are disabled depending on 'disable_break' value. Returns a tuple of value and type both as str. Note that - depending on the CGI_ESCAPE_EVALUATE_OUTPUT attribute - value is escaped. """

        if disable_break:
            breakpoints_backup = IKBreakpoint.backup_breakpoints_state()
            IKBreakpoint.disable_all_breakpoints()

        if frame_id and not global_context:
            eval_frame = ctypes.cast(frame_id, ctypes.py_object).value
            global_vars = eval_frame.f_globals
            local_vars = eval_frame.f_locals
        else:
            global_vars = None
            local_vars = None

        try: 
            result = eval(expression, global_vars, local_vars)
            result_type = IKPdbRepr(result)
            result_value = repr(result)
        except SyntaxError:
            # eval() failed, try with exec to handle statements
            try:
                result = exec(expression, global_vars, local_vars)
                result_type = IKPdbRepr(result)
                result_value = repr(result)
            except Exception as e:
                t, result = sys.exc_info()[:2]
                if isinstance(t, str):
                    result_type = t
                else: 
                    result_type = str(t.__name__)
                result_value = "%s: %s" % (result_type, result,)
        except:
            t, result = sys.exc_info()[:2]
            if isinstance(t, str):
                result_type = t
            else: 
                result_type = t.__name__
            result_value = "%s: %s" % (result_type, result,)

        if disable_break:
            IKBreakpoint.restore_breakpoints_state(breakpoints_backup)

        _logger.e_debug("evaluate(%s) => result_value=%s, result_type=%s, result=%s", 
                        expression, 
                        result_value, 
                        result_type, 
                        result)
        if self.CGI_ESCAPE_EVALUATE_OUTPUT:
            result_value = cgi.escape(result_value)
        
        # We must check that result is json.dump compatible so that it can be sent back to client.
        try:
            json.dumps(result_value)
        except:
            t, result = sys.exc_info()[:2]
            if isinstance(t, str):
                result_type = t
            else: 
                result_type = t.__name__
            result_value = "<plaintext>%s: IKP3db is unable to JSON encode result to send it to "\
                           "debugging client.\n"\
                           "  This typically occurs if you try to print a string that cannot be"\
                           " decoded to 'UTF-8'.\n"\
                           "  You should be able to evaluate result and inspect it's content"\
                           " by removing the print statement." % result_type
        return result_value, result_type